我试图得到一个3列的设计,没有使用任何浮动。
<header>This is a Header</header>
<div id="body">
<div id="col-1" class="col">this is a column - this is a column - this is a column - this is a column</div>
<div id="col-2" class="col">this is a column - this is a column - this is a column - this is a column</div>
<div id="col-3" class="col">this is a column - this is a column - this is a column - this is a column</div>
</div>CSS
* {
margin:0;
padding:0;
}
header {
background:#4679BD;
width:90%;
height:70px;
line-height:70px;
font-size:20px;
text-align:center;
border:1px solid #333;
margin:10px auto;
}
#body {
width:700px;
margin:auto;
border:1px solid #333;
}
#body .col {
display:inline-block;
background:#ccc;
height:500px;
border:1px solid #333;
margin:5px;
}
#body #col-1 {
width:100px;
}
#body #col-2 {
width:200px;
}
#body #col-3 {
width:350px;
}http://jsfiddle.net/chaos67731/fmZpr/5/
当我在类".col“上给列一个宽度时,所有列都停留在顶部,但是当我通过ID给每个列一个宽度并使它们不同时,它们就会像上面的链接中所看到的那样执行步骤。
解决这个问题的方法是什么?为什么会发生这种情况?
发布于 2013-10-07 04:40:46
默认情况下,inline-block元素的垂直对齐方式是baseline。
只需在vertical-align:top上设置.col即可。
#body .col {
vertical-align: top;
}发布于 2013-10-07 07:00:24
使用这个
{
vertical-align: top;
}https://stackoverflow.com/questions/19217145
复制相似问题