inside div tag I have a 32*32 icon and next to it a short text. But text is in bottom next to icon, I want to align the text in middle next to icon. How can I do it? I added vertical-align:middle to class too but nothing changed. Should I have icon and text in 2 separate div classes that both are inside a div themselves? please advice.
It’s hard to say without seeing what you have done in your html.
It may be that you only need to apply vertical-align to the image itself. Setting v-align on the parent element does not work, it applies to the elements that need to align.
Something like this –
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>vertical-align</title>
<style>
.something span,
.something img {
display:inline-block;
vertical-align:middle;
width:32px;
height:32px;
background:red;
}
</style>
</head>
<body>
<div class="something">
<p>Text to v-align with image <span></span> Text to v-align with image</p>
</div>
</body>
</html>
Personaly I think you are asking the wrong question.
You want to center the text with the icon, but I would advice you to center the icon with the text.
Text will change more easily in length (& thus space taken) then an icon with most likely fixed dimensions.
If you make the block responsive, the likeliness the height of the text changes is bigger.
It could be the icon is bigger then the text now, but that’s easily solved with some padding on the text. Chances are high that the text will become bigger then the icon, when the block gets smaller.
But if you want the CSS code for what works, you’ll have to give us your HTML as well, especially how you thought about putting the icon in there (Is it a background-image, icon font, img or object ? )