【发布时间】:2019-08-15 19:42:18
【问题描述】:
容器周围和两列之间似乎有一个填充物。我该如何摆脱它们?
我尝试将边距和内边距设置为 0,但没有成功。
body,
html {
width: 100%;
height: 100%;
}
main {
display: flex;
flex-flow: row wrap;
justify-content: center;
width: 100%;
}
.flexbox img {
width: 100%;
height: auto;
}
@media all and (max-width: 650px) {
.flexbox {
width: 100%;
}
}
@media all and (min-width: 651px) {
.col-1,
.col-2 {
width: 50%;
}
.col-3 {
width: 100%;
}
}
<main id="container">
<div class="flexbox col-1">
<img src="http://placehold.it/800x400/f00/000?text=1" />
</div>
<div class="flexbox col-2">
<img src="http://placehold.it/800x400/0f0/000?text=2" />
</div>
<div class="flexbox col-3">
<img src="http://placehold.it/800x400/06f/000?text=3" />
</div>
</main>
提前谢谢你!
【问题讨论】:
-
这就是它发生的原因,因为 img 是内联的。将
display: block;添加到.flexbox img -
谢谢@GrzegorzT。那行得通,我添加了 margin: 0;到 html 以摆脱边框。