我有以下网格系统:
http://jsfiddle.net/tev60L6z/1
html {
box-sizing: border-box;
}
*,
*:before,
*:after {
box-sizing: inherit;
}
img {
height: auto;
max-width: 100%;
}
.container {
width: 100%;
}
.third {
float: left;
width: 33.334%;
padding-right: 24px;
}
.last {
padding-right: 0;
}
.clearfix:before,
.clearfix:after {
content: "";
display: table;
}
.clearfix:after {
clear: both
}
<div class="container clearfix">
<article class="third">
<img src="http://3.bp.blogspot.com/-6Q23mHrTwxc/UxGT360FBMI/AAAAAAAAAJ0/pj86RO2vGyg/s320/google-maps-api.jpg" alt="image" />
<h1>Title</h1>
<p>Description</p>
</article>
<article class="third">
<img src="http://3.bp.blogspot.com/-6Q23mHrTwxc/UxGT360FBMI/AAAAAAAAAJ0/pj86RO2vGyg/s320/google-maps-api.jpg" />
<h1>Title</h1>
<p>Description</p>
</article>
<article class="third last">
<img src="http://3.bp.blogspot.com/-6Q23mHrTwxc/UxGT360FBMI/AAAAAAAAAJ0/pj86RO2vGyg/s320/google-maps-api.jpg" alt="image" />
<h1>Title</h1>
<p>Description</p>
</article>
</div>
3 列在我的容器中的位置相同,但最后一张图像的高度大于其余图像。我知道这是因为第三列没有填充。
有没有办法在保持 3 个相等宽度的同时均衡图像高度?我已经在图像上尝试了 max-width
,但这会在第三列的右侧增加一个 24px 的间隙。
最佳答案
我建议在最后一个元素上保留填充并在容器上使用负右边距:
html {
box-sizing: border-box;
}
*,
*:before,
*:after {
box-sizing: inherit;
}
img {
height: auto;
max-width: 100%;
}
.container {
width: 100%;
overflow: hidden;
}
.wrap {
margin-right: -24px;
}
.third {
float: left;
width: 33.334%;
padding-right: 24px;
}
.clearfix:before,
.clearfix:after {
content: "";
display: table;
}
.clearfix:after {
clear: both
}
<div class="container clearfix">
<div class="wrap">
<article class="third">
<img src="http://3.bp.blogspot.com/-6Q23mHrTwxc/UxGT360FBMI/AAAAAAAAAJ0/pj86RO2vGyg/s320/google-maps-api.jpg" alt="image" />
<h1>Title</h1>
<p>Description</p>
</article>
<article class="third">
<img src="http://3.bp.blogspot.com/-6Q23mHrTwxc/UxGT360FBMI/AAAAAAAAAJ0/pj86RO2vGyg/s320/google-maps-api.jpg" />
<h1>Title</h1>
<p>Description</p>
</article>
<article class="third last">
<img src="http://3.bp.blogspot.com/-6Q23mHrTwxc/UxGT360FBMI/AAAAAAAAAJ0/pj86RO2vGyg/s320/google-maps-api.jpg" alt="image" />
<h1>Title</h1>
<p>Description</p>
</article>
</div>
</div>
关于html - 具有填充图像问题的响应式网格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27312870/