1

我知道这个问题已经被问过很多次了,但没有一个解决方案对我有用。我只是想在一个与 twitter-bootstrap 类相关联的 div 中对齐一个标签。但它没有被对齐。我已经尝试过水平对齐,它工作正常。没有引导它工作正常,但使用引导它停止工作。知道它将如何工作吗?

4

4 回答 4

1

改为使用标签

.center{
    width: 100px;
    height: 100px;
    border: 1px solid red;
    display: table;
}
.center label {
    display: table-cell; 
    vertical-align: middle;
}

分叉的 jsFiddle http://jsfiddle.net/s5dJH/

于 2013-06-21T12:19:03.350 回答
0

You can use line-height to your label and set it the same height as your div. This will align it perfectly.

See this demo.

于 2013-06-21T12:04:05.773 回答
0

干得好

使用

display:table;

display:table-cell;
vertical-align:middle;

这样标签将始终居中,即使您调整框的大小

http://jsfiddle.net/s7Wb4/2/

于 2013-06-21T12:05:14.173 回答
0

尝试这个

http://jsfiddle.net/s7Wb4/9/

.center{
width : 100px;
height : 100px;
display : table-cell;
float:none !important;
vertical-align : middle;
border : 1px solid red;
}
于 2013-06-21T12:31:13.363 回答