vertical-alignment - 元素不遵守垂直对齐 : bottom, 为什么?

标签 vertical-alignment css

为什么中间元素不遵守vertical-align规则?

我怎样才能让它这样做?

例子:

<div id="outer">
  <!-- why doesn't this obey its inline-block and snap to bottom? -->
  <div id="inner">From The Smiths</div>
</div>

CSS:

#outer{
top: 0.452873563218px; 
left: 23.8988505747126px; 
transform: rotate(0deg); 
-webkit-transform: rotate(0deg); 
width: 284.88275862069px; 
height: 58.8229885057471px; 
z-index: 5; 
font-size: 8.81226053639847px; 
position: absolute; 
overflow: hidden;
margin: 0;
padding: 0;
}

#inner{
top: 0px;  
left: 0px; 
font-family: 'Open Sans'; 
text-align: center; 
vertical-align: bottom; 
color: rgb(140, 149, 157); 
font-weight: 300; 
font-size: 8.81226053639847px; 
position: relative; 
display: inline-block; 
width: 100%;
margin: 0;
height: 10px;
padding: 0;
overflow: hidden;

jsbin 链接:http://jsbin.com/mavuhikifi/2/

最佳答案

您可以将外部 div 设置为 display:table,将内部 div 设置为 display:table-cell

#outer {
    top: 0.452873563218px;
    left: 23.8988505747126px;
    transform: rotate(0deg);
    -webkit-transform: rotate(0deg);
    width: 284.88275862069px;
    height: 58.8229885057471px;
    z-index: 5;
    font-size: 8.81226053639847px;
    position: absolute;
    overflow: hidden;
    margin: 0;
    padding: 0;
    display: table;
}
#inner {
    top: 0px;
    left: 0px;
    font-family:'Open Sans';
    text-align: center;
    vertical-align: bottom;
    color: rgb(140, 149, 157);
    font-weight: 300;
    font-size: 8.81226053639847px;
    position: relative;
    display: table-cell;
    width: 100%;
    margin: 0;
    height: 10px;
    padding: 0;
    overflow: hidden;
}
<div id="outer">
    <!-- why doesn't this obey its inline-block and snap to bottom? -->
    <div id="inner">From The Smiths</div>
</div>

或者像 jsFiddle那样使用绝对/相对定位.

关于vertical-alignment - 元素不遵守垂直对齐 : bottom, 为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26475962/

相关文章:

jquery - 悬停时更改显示属性

html - 垂直响应设计 : Scaling an image proportionally in div

html - 垂直对齐 TD 中的所有(!)元素?

android - Android中的垂直(旋转)标签

html - 下拉菜单在 Firefox 移动浏览器上显示不同

css - 单击 Vuejs + Tailwind CSS 时如何更改下拉菜单

jquery - 无法滚动网站上的内容

c# - 垂直代码对齐 VS Visual Studio 2015 自动格式化

CSS:向右浮动 div 会导致容器 div 在 IE 中拉伸(stretch)整个屏幕宽度

javascript - 网站加载速度和 Bootstrap "Carousel"图片加载