请参阅:http://jsfiddle.net/b2BpB/1/
问:如何让box1和box3对齐父div的顶部boxContainer?
#boxContainerContainer {
background: #fdd;
text-align: center;
}
#boxContainer {
display: inline-block;
border: thick dotted #060;
margin: 0px auto 10px auto;
text-align: left;
}
#box1 {
width: 50px;
height: 50px;
background: #999;
display: inline-block;
}
#box2 {
width: 50px;
height: 100px;
background: #999;
display: inline-block;
}
#box3 {
width: 50px;
height: 50px;
background: #999;
display: inline-block;
}
Run Code Online (Sandbox Code Playgroud)
非常感谢...
致谢:这个问题来自之前由/sf/users/1440491/给出的答案 :获取CSS元素以自动调整内容宽度,同时居中
rhi*_*ino 364
试试vertical-alignCSS属性.
#box1 {
width: 50px;
height: 50px;
background: #999;
display: inline-block;
vertical-align: top; /* here */
}
Run Code Online (Sandbox Code Playgroud)
也适用它#box3.
使用vertical-align:top; 对于你想要在顶部的元素,正如我在你的jsfiddle上所展示的那样.
http://www.brunildo.org/test/inline-block.html