如何使第一个.item
(绿色框)的高度为100%?
* {
box-sizing: border-box;
}
.wrap {
display: flex;
flex-wrap: wrap;
}
.item {
border: 1px solid red;
background: #8282e0;
width: 50%;
}
.item:nth-child(1) {
background: #a6f7a6;
height: 100%;
}
.item:nth-child(3) {
margin-left: 50%;
}
<div class="wrap">
<div class="item">
<h3>Item Title</h3>
</div>
<div class="item">
<h3>Item Title</h3>
</div>
<div class="item">
<h3>Item Title</h3>
</div>
</div>
答案 0 :(得分:2)
这就是我要这样做的方式(如果您需要将三个标头完全放在下面,例如使用for循环呈现它们,我不知道一种使其工作的方法)
* {
box-sizing: border-box;
}
.wrap {
display: flex;
flex-wrap: wrap;
flex-direction: row;
flex: 1;
}
.itemCont {
display: flex;
background: #8282e0;
flex: 1;
flex-direction: column;
}
.item {
display: flex;
border: 1px solid red;
background: #5691f3;
flex: 1;
}
<div class="wrap">
<div class="itemCont">
<div class="item">
<h3>Item Title</h3>
</div>
</div>
<div class="itemCont">
<div class="item">
<h3>Item Title</h3>
</div>
<div class="item">
<h3>Item Title</h3>
</div>
</div>
</div>
答案 1 :(得分:1)
这可以通过将flex-direction
更改为column
并将固定高度应用于.wrap
* {
box-sizing: border-box;
}
.wrap {
display: flex;
flex-wrap: wrap;
flex-direction: column;
height: 123px;
}
.item {
border: 1px solid red;
background: #8282e0;
width: 50%;
}
.item:nth-child(1) {
background: #a6f7a6;
height: 100%;
}
<div class="wrap">
<div class="item">
<h3>Item Title</h3>
</div>
<div class="item">
<h3>Item Title</h3>
</div>
<div class="item">
<h3>Item Title</h3>
</div>
</div>
答案 2 :(得分:1)
* {
box-sizing: border-box;
}
.wrap {
display: flex;
flex-wrap: wrap;
}
.item {
border: 1px solid red;
background: #8282e0;
flex:1;
}
.item-inner {
flex: 1;
justify-content:center;
height:100px;
}
.wrap-inner{
display: flex;
flex-wrap: wrap;
flex-direction:column;
}
.item:nth-child(1) {
background: #a6f7a6;
height: 200px;
}
.item:nth-child(3) {
margin-left: 50%;
}
<div class="wrap">
<div class="item item-outer">
<h3>Item Title</h3>
</div>
<div class="item wrap-inner">
<div class="item-inner">
<h3>Item Title</h3>
</div>
<div class="item-inner">
<h3>Item Title</h3>
</div>
</div>
</div>
这很容易使用flex
属性并更改高度。
答案 3 :(得分:1)
不需要多余的CSS,只需更改结构并根据需要提供背景颜色即可。
* {
box-sizing: border-box;
}
.wrap {
display: flex;
flex-wrap: wrap;
}
.item {
border: 1px solid red;background: #8282e0;
}
.wrap > .item{width: 50%;}
<div class="wrap">
<div class="item">
<h3>Item Title</h3>
</div>
<div class="item">
<div class="item">
<h3>Item Title</h3>
</div>
<div class="item">
<h3>Item Title</h3>
</div>
</div>
</div>