我正在尝试使用 CSS 制作一个漂亮的网格布局,但无法让它们以 3 行显示,单个列行为 33.3333%
我要使用的网格样式是 this .
这是我目前的代码;
HTML:
<section id="web">
<div class="row">
<span class="web large-3 columns"><img src="images/1.gif"></span>
<span class="web large-3 columns"><img src="images/2.jpg"></span>
<span class="web large-3 columns"><img src="images/3.png"></span>
</div>
<div class="row">
<span class="web large-3 columns"><img src="images/4.jpg"></span>
<span class="web large-3 columns"><img src="images/5.png"></span>
<span class="web large-3 columns"><img src="images/6.jpg"></span>
</div>
</section>
CSS:
section { display: block; }
section#web {
background: #f8f8f8;
padding: 80px 0;
}
.row {
width: 100%;
margin: 0 auto;
max-width: 1144px;
}
span.web {
margin-bottom: 20px;
text-align: center;
position: relative;
border: 1px solid #e3e3e3;
}
.row .large-3 {
position: relative;
width: 33.33333%;
}
.row .columns {
position: relative;
padding-left: .83333em;
padding-right: .83333em;
width: 100%;
float: left;
}
我的 JSFiddle .
最佳答案
您将宽度设置为像素。相反,您应该使用百分比,例如 width: 33%。对于此布局,33.3 是一个糟糕的选择,因为您应用了 20px 的边距。也许 28% 就可以了。
fiddle :http://jsfiddle.net/Vfffg/119/
.container > div {
margin: 20px;
width: 28%;
height: 100px;
background: blue;
float: left;
color: #fff;
text-align: center;
}
关于css - 使用图像创建 CSS 网格布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24708167/