问题
I'm trying to align a Text next to an Icon/Image, I want the text or the image to be align vertically but the vertical-align is not being applied, it might have something to do with the floats
Here's an image explainng what I want to do:
Here's what I have so far:
---- HTML ---
<ul class="toolboxItems">
<li>
<div class="image">
<img src="someImage.png">
</div>
<div class="label">
<label>Lorem ipsum dolor sit amet....</label>
</div>
<li>
<li>
/* more of the same .... */
</li>
<ul>
---- CSS ----
ul.toolboxItems li {margin-bottom:10px;}
.image {float:left; width:30px;}
.label {float:left; width:150px; vertical-align:middle;}
I tried using display:table / table-cell but it did not work.
回答1:
You could use the CSS table display properties which are supported in everything (besides IE 7 or below).
Working demo here: http://jsfiddle.net/Hgssm/1/
.toolboxItems {
display: table;
}
.toolboxItems li {
display: table-row;
}
.toolboxItems .image,
.toolboxItems .label {
display: table-cell;
width: 30px;
vertical-align: middle;
}
.toolboxItems .label {
width: 150px;
}
来源:https://stackoverflow.com/questions/13018996/css-vertically-align-text-next-to-icon-using-floating-divs