gpt4 book ai didi

html - CSS 显示 :inline-block | 3 columns | No floats

转载 作者:搜寻专家 更新时间:2023-10-31 22:03:00 25 4
gpt4 key购买 nike

我正在尝试获得 3 列设计,但不使用任何 float 。

HTML

<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 给每列一个宽度并使它们不同时,它们的步骤就像您将在链接中看到的那样多于。

有什么解决办法,为什么会这样?

最佳答案

默认情况下,inline-block 元素的垂直对齐方式是baseline

只需在 .col 上设置 vertical-align:top

#body .col {
vertical-align: top;
}

Working jsFiddle here

关于html - CSS 显示 :inline-block | 3 columns | No floats,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19217145/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com