HTML – 如何使内嵌块框粘在顶部?

前端之家收集整理的这篇文章主要介绍了HTML – 如何使内嵌块框粘在顶部?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
参见英文答案 > My inline-block elements are not lining up properly5个
我试着让蓝色容器贴在上面.我该如何管理?

HTML:

<div class="container">
    <div class="a">blue</div>
    <div class="b">green</div>
</div>

CSS:

.a {
    width:100px;
    height:400px;
    display:inline-block;
    background-color:blue;
}
.b {
    width:400px;
    height:600px;
    display:inline-block;
    background-color: green;
}
.container {
    vertical-align:top;
}

http://jsfiddle.net/xswa4/

vertical-align: top;

不起作用……

解决方法

您应该在元素.a本身上使用 vertical-align:top;,而不是父.container:
.a {
    display:inline-block;
    background-color:blue;
    vertical-align:top;
}

JSFiddle Demo

原文链接:https://www.f2er.com/html/223810.html

猜你在找的HTML相关文章