CSS: Vertically Align Text next to Icon using Floating Divs

陌路散爱 提交于 2021-01-28 02:37:18

问题


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: enter image description here

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!