Han*_*Sun 6 html css vertical-alignment twitter-bootstrap
DEMO可在以下位置找到:
http://www.bootply.com/VZ7gvA7ndE#
我将高度设置div
为100px,并希望显示label
在底部div
.我用
#contain-word-lab {
vertical-align: bottom;
margin-bottom: 5px;
}
Run Code Online (Sandbox Code Playgroud)
但是,这根本不起作用.将label
仍然对齐的顶部div
.
有没有人对此有任何想法?为什么vertical-align
不在这里工作?谢谢!
Has*_*ami 22
vertical-align: bottom
不单独工作由于父元素的高度大于标签的计算高度,因此"使用" vertical-align: bottom
不会将该(内联)元素移动到父元素的底部.
因为在内联流中,vertical-align
根据父级的基线确定元素的定位方式; 在标签上使用该属性不会改变其父级的基线位置.
默认情况下inline
,内联级别元素(,inline-block
)位于其基线中.如果他们有不同的高度,最高的元素将决定其他人应该放在哪里.
即在内联流中,最高元素将影响/移动父级的基线:
因此,在父项具有显式的height
情况下,如果我们可以使内联子项具有与父项(全高子项)完全相同的高度,则会影响内联流并将基线向下移动:
并且为了在父母中保留元素(包括具有下行字母的字母),我们应该通过vertical-align: bottom;
声明将它们垂直对齐.
baseline
将框的基线与父框的基线对齐.如果框没有基线,请将底部边距边缘与父级基线对齐.
bottom
将对齐子树的底部与线框底部对齐.
因此,您可以在父级中创建一个全高元素(我个人更愿意使用伪元素)来对齐底部的标签.
#contain-word-div:after {
content: "";
display: inline-block;
height: 100%; /* Let it be as height as the parent */
vertical-align: bottom; /* Align the element at the bottom */
}
#contain-word-lab {
display: inline-block;
vertical-align: bottom; /* Align the element at the bottom */
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
26394 次 |
最近记录: |