问题
We have four children in one parent. And I want to make effect which you see on the picture.
<article class="parent">
<figure class="child">
<img src="img/example.jpg" alt="" />
<figcaption">
<p>description</p>
</figcaption>
</figure>
<figure class="child">
<img src="img/example.jpg" alt="" />
<figcaption">
<p>description</p>
</figcaption>
</figure>
<figure class="child">
<img src="img/example.jpg" alt="" />
<figcaption">
<p>description</p>
</figcaption>
</figure>
<figure class="child">
<img src="img/example.jpg" alt="" />
<figcaption">
<p>description</p>
</figcaption>
</figure>
</article>
The child have one constant parameter width: 300px;
But we cannot edit the html (+div).
We can use only CSS for that thing. Is that possible?
My English is poor sry :)
回答1:
Maybe something like this? https://codepen.io/jnnkm/pen/jVwZrX
.parent {
display: flex;
flex-direction: row;
flex-wrap: wrap;
width: 800px;
}
@media only screen and (min-device-width: 1000px) {
.parent {
width: initial;
}
}
回答2:
Good evening The Agropl!
Maybe this is something that can help you in the right direction - im still new to using flexbox, so if this can be done more correct, feel free to correct me. :)
http://codepen.io/andreastherkildsen/pen/pNeajo
<div class="flex-container">
<div class="flex-item">
<h3>1</h3>
<p>Lorem ipsum, Lorem ipsum,Lorem ipsum,Lorem ipsum,Lorem ipsum,Lorem ipsum,Lorem ipsum,Lorem ipsum,</p>
</div>
<div class="flex-item">
<h3>1</h3>
<p>Lorem ipsum, Lorem ipsum,Lorem ipsum,Lorem ipsum,Lorem ipsum,Lorem ipsum,Lorem ipsum,Lorem ipsum,</p>
</div>
<div class="flex-item">
<h3>1</h3>
<p>Lorem ipsum, Lorem ipsum,Lorem ipsum,Lorem ipsum,Lorem ipsum,Lorem ipsum,Lorem ipsum,Lorem ipsum,</p>
</div>
<div class="flex-item">
<h3>1</h3>
<p>Lorem ipsum, Lorem ipsum,Lorem ipsum,Lorem ipsum,Lorem ipsum,Lorem ipsum,Lorem ipsum,Lorem ipsum,</p>
</div>
</div>
and the style
.flex-container{
height: 500px;
background: blue;
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
align-items: baseline;
-webkit-flex-flow: row wrap;
justify-content: space-around;
}
.flex-item{
background: tomato;
width: 300px;
height: auto;
margin-top: 10px;
color: white;
font-weight: bold;
text-align: center;
display: flex;
}
.flex-item h3{
font-size: 50px;
padding-left: 50px;
}
.flex-item p{
font-size: 16px;
padding-left: 50px;
}
@media all and (max-width: 1230px) {
.flex-item{
padding-right:100px;
}
}
来源:https://stackoverflow.com/questions/40794461/flex-box-two-boxes-wrap-when-scaling-window-browser