1 回答
TA贡献1820条经验 获得超2个赞
无需复杂化nth-child
。您可以使用伪元素在中间简单地画一条线。
* {box-sizing: border-box;}
.flex-container {
width: 90%;
margin: 5px auto;
display: flex;
background-color: #ddd;
flex-wrap: wrap;
position:relative;
}
.flex-container:before {
content:"";
position:absolute;
top:0;
bottom:0;
left:50%;
width:1px;
background:red;
}
.flex-container>div {
background-color: #f1f1f1;
padding: 5px;
font-size: 12px;
cursor: pointer;
text-align: center;
width: 50%;
border-bottom: solid 1px #ccc;
}
<div class="flex-container">
<div id="flex1" style="display: block;">TEST 1</div>
<div id="flex2" style="display: block;">TEST 2</div>
<div id="flex3" style="display: block;">TEST 3</div>
<div id="flex4" style="display: block;">TEST 4</div>
<div id="flex5" style="display: block;">TEST 5</div>
</div>
<input type="button" onclick="document.getElementById('flex1').style.display = document.getElementById('flex1').style.display === 'none' ? 'block' : 'none'" value="Flex1" />
这是使用 CSS 网格的另一个想法:
* {box-sizing: border-box;}
.flex-container {
width: 90%;
margin: 5px auto;
display: grid;
grid-template-columns:1fr 1fr;
grid-column-gap:1px;
background:
linear-gradient(red,red) center/1px 100% no-repeat,
#ddd;
}
.flex-container>div {
background-color: #f1f1f1;
padding: 5px;
font-size: 12px;
cursor: pointer;
text-align: center;
border-bottom: solid 1px #ccc;
}
<div class="flex-container">
<div id="flex1" style="display: block;">TEST 1</div>
<div id="flex2" style="display: block;">TEST 2</div>
<div id="flex3" style="display: block;">TEST 3</div>
<div id="flex4" style="display: block;">TEST 4</div>
<div id="flex5" style="display: block;">TEST 5</div>
</div>
<input type="button" onclick="document.getElementById('flex1').style.display = document.getElementById('flex1').style.display === 'none' ? 'block' : 'none'" value="Flex1" />
添加回答
举报