简体   繁体   English

列表元素内的文本和div垂直对齐

[英]Text and div vertical aligning inside a list element

I have the following layout: 我有以下布局:

<ul>
    <li>Text
        <div class="task"></div>
    </li>
</ul>

See fiddle . 小提琴 I am having problems aligning the text Text . 我在对齐文本Text时遇到问题。 Now it is on the same line as the div . 现在它与div在同一行。 I would like to align (vertically) the Text to the middle of the div . 我想将Text (垂直)对齐到div的中间。 I have tried nesting the Text inside a span and giving the span margin-bottom, padding-bottom , but nothing seems to work. 我尝试将Text嵌套在一个span并给该span margin-bottom, padding-bottom ,但似乎没有任何效果。

.task {
    height:20px;
    width:20px;
    background-color:red;
    display:inline-block;
    text-align:center;
    float:none;
}

ul li {
    text-align:center;
    width:50px;
    display:block;
    list-style:none;
}

I just set a width on the LI to match what the size of the box was (then reduced the size of the box to make sure it centered) and applied display:block;text-align:center; 我只是在LI上设置一个宽度以匹配框的大小(然后减小框的大小以确保其居中),然后应用display:block; text-align:center; to center everything. 集中一切。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM