[英]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
,但似乎没有任何效果。
Beware of spacing issues with inline-block - http://robertnyman.com/2010/02/24/css-display-inline-block-why-it-rocks-and-why-it-sucks/ 小心内联块的间距问题-http ://robertnyman.com/2010/02/24/css-display-inline-block-why-it-rocks-and-why-it-sucks/
http://jsfiddle.net/6AxbH/1/ http://jsfiddle.net/6AxbH/1/
.task {
display:inline-block;
vertical-align: middle;
}
.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.