<template>
<div class="container">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
<div class="item">4</div>
</div>
</template>
<style lang="scss" scoped>
.container {
border: 3px solid red;
width: 600px;
height: 300px;
margin: 30px;
display: flex;
flex-wrap: wrap;
.item {
display: flex;
justify-content: center;
align-items: center;
box-sizing: border-box;
width: 50%;
height: 50%;
background-color: yellow;
border-right: 3px solid white;
border-top: 3px solid white;
// 父元素中的偶数个子元素
&:nth-child(2n) {
border-right: 0 none;
}
// 父元素的前两个子元素(即第1和第2个item)
&:nth-child(-n + 2) {
border-top: 0 none;
}
}
}
</style>