gpt4 book ai didi

html - 简单的 CSS\HTML DIV 布局问题

转载 作者:行者123 更新时间:2023-11-27 23:48:32 26 4
gpt4 key购买 nike

希望有人能在这里提供帮助 - 一直试图让它工作一段时间但一无所获。

我正在玩一个简单的(或看起来如此)CSS\HTML 布局,它将在左侧显示一个大的 (500px) 框,旁边显示六个较小的 (250px) 框。像这样:

|----|--|--|--|
| | | | |
| |--|--|--|
| | | | |
|----|--|--|--|

但无论我如何尝试,第二行较小的盒子总是跳到较大的盒子下面,而不是坐在第一排下面。更像这样:

|----|--|--|--|
| | | | |
| |--|--|--|
| |
|----|---
| | | |
|__|__|__|

我已经在下面复制了我的标记 - 我可能在这里遗漏了一些非常明显的东西,所以欢迎任何帮助(这里的虚线边框更多是为了我自己的理智,所以我可以看到每个 DIV 的布局) .

#contentbox {
max-width:1300px;
border:1px dashed blue;
text-align:center;
font-size:0;
margin: 4% auto;
}
#bigbox {
width:500px;
height:500px;
border:1px dashed blue;
display:inline-block;
}
#box {
width:250px;
height:250px;
border:1px dashed blue;
display:inline-block;
vertical-align:top;
}
<!DOCTYPE html>

<head>
<link rel="stylesheet" type="text/css" href="stylesheet.css">

<title></title>
</head>

<body>
<div id="contentbox">
<div id="bigbox"></div>
<div id="box"></div>
<div id="box"></div>
<div id="box"></div>
<div id="box"></div>
<div id="box"></div>
<div id="box"></div>
</div>

</body>

</html>

JSFiddle

最佳答案

您可以使用float 代替inline-block。此外,ID 必须是唯一的,而不是使用类名来引用多个元素:

#contentbox {
width: 1000px;
border: 1px dashed blue;
text-align: center;
font-size: 0;
margin: 4% auto;
}
.bigbox {
width: 500px;
height: 750px;
border: 1px dashed blue;
float: left;
box-sizing: border-box;
}
.box {
box-sizing: border-box;
width: 250px;
height: 250px;
border: 1px dashed blue;
float: left;
}
/*Clear Floats*/
#contentbox:after {
content: " ";
display: Table;
clear: both;
}
<div id="contentbox">
<div class="bigbox"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
</div>

关于html - 简单的 CSS\HTML DIV 布局问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28479560/

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