【发布时间】:2018-04-15 14:03:54
【问题描述】:
我有 10 个 div:2 个隐藏,8 个堆叠在一起。
使用媒体查询,在调整屏幕大小时,我可以显示 2 个隐藏的 div。
所以,现在我在底部有 4 个红色 div,但我希望它们成对出现 - 2 行,2 个红色 div 彼此相邻。
我该怎么做?
html {
font-size: 20px;
}
.box {
color: white;
font-size: 100px;
text-align: center;
text-shadow: 4px 4px 0 rgba(0, 0, 0, 0.1);
padding: 10px;
Margin: 5px;
/* width: calc(33.33% - 10px);*/
}
/* Flexbox code starts here */
.container {
display: flex;
/*Must!!!! on the container, in order to turn it to flex*/
flex-direction: column;
flex-wrap: wrap;
justify-content: center;
}
/* Colors for each box */
.blue {
background: blue;
}
.orange {
background: Orange;
height: 300px;
}
.green {
background: green;
}
.red {
background: red;
height: 170px;
}
.hide-reds {
display: none;
}
/*Media Queries for Different Screen Sizes*/
@media all and (min-width: 800px) {
.red {
display: block;
}
}
<div class="container">
<div class="box blue">Blue</div>
<div class="box blue">Blue</div>
<div class="box orange">Orange</div>
<div class="box green">Green</div>
<div class="box green">Green</div>
<div class="box green">Green</div>
<div class="box red">Red</div>
<div class="box red">Red</div>
<div class="box red hide-reds">Red</div>
<div class="box red hide-reds">Red</div>
</div>
【问题讨论】:
-
一切正常。
标签: html css flexbox media-queries