【发布时间】:2020-06-22 06:49:13
【问题描述】:
我有一组内联块,我希望在第 4 个块之后让它从新行开始。到目前为止,这是我的项目,对 CSS 来说有点新,所以任何帮助都令人惊叹!
https://codepen.io/lumin-little/pen/poJpOMN
HTML 部分
<div class="item-showcase">
<article class="showcase">
<div class="image">
<img src="https://images.unsplash.com/photo-1583803163205-847ab09b42fe?ixlib=rb-1.2.1&auto=format&fit=crop&w=1350&q=80.jpg" id="puppo">
</div>
<h3>Example text #1</h3>
</article>
<div class="showcase">
<div class="image">
<img src="https://images.unsplash.com/photo-1583803163205-847ab09b42fe?ixlib=rb-1.2.1&auto=format&fit=crop&w=1350&q=80.jpg" id="puppo">
</div>
<h3>Example text #2</h3>
</div>
<article class="showcase">
<div class="image">
<img src="https://images.unsplash.com/photo-1583803163205-847ab09b42fe?ixlib=rb-1.2.1&auto=format&fit=crop&w=1350&q=80.jpg" id="puppo">
</div>
<h3>Example text #3</h3>
</article>
<article class="showcase">
<div class="image">
<img src="https://images.unsplash.com/photo-1583803163205-847ab09b42fe?ixlib=rb-1.2.1&auto=format&fit=crop&w=1350&q=80.jpg" id="puppo">
</div>
<h3>Example text #4</h3>
</article>
<article class="showcase">
<div class="image">
<img src="https://images.unsplash.com/photo-1583803163205-847ab09b42fe?ixlib=rb-1.2.1&auto=format&fit=crop&w=1350&q=80.jpg" id="puppo">
</div>
<h3>Example text #5</h3>
</article>
<article class="showcase">
<div class="image">
<img src="https://images.unsplash.com/photo-1583803163205-847ab09b42fe?ixlib=rb-1.2.1&auto=format&fit=crop&w=1350&q=80.jpg" id="puppo">
</div>
<h3>Example text #6</h3>
</article>
</div>
CSS 部分
.item-showcase
{
padding-top:50px;
padding-left:100px;
}
.showcase
{
display:inline-block;
background:red;
padding:20px 20px 80px 20px;
}
#puppo
{
width:250px;
height:200px;
object-fit: cover;
}
.showcase:nth-child(4n)
{
background:green;
}
谢谢大家,晚安???
【问题讨论】:
-
考虑使用flexbox
-
听起来更像是 Grid 而不是 inline-block 的工作
-
可以做类似
.item-showcase:nth-child(4n-1)::after{display: block; content: '';}或类似的事情吗?
标签: html css block inline display