您好,重现此
:root{
--black: rgb(11, 14, 17);
--green: rgb(112, 228, 80);
--gray: rgb(55, 55, 55);
}
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}
body{
width: 100%;
height: 100%;
background-color: var(--black);
color: #eee;
}
#rect-bar{
width: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
border-radius: 15px;
overflow: hidden;
}
#rect-bar .rect-row{
width: 100%;
height: 150px;
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
/* border: 1px solid white; */
}
#rect-bar .rect-row .rect-cube{
margin: 5px;
width: 150px;
height: 150px;
border-radius: 15px;
background-color: var(--green);
/* border: 1px solid white; */
}
#rect-bar .rect-row .rect-cube.rcg{
width: 120px;
height: 120px;
background-color: var(--gray);
}
<div id="rect-bar">
<div class="rect-row">
<div class="rect-cube rcg">
</div>
<div class="rect-cube">
</div>
</div>
<div class="rect-row">
<div class="rect-cube">
</div>
<div class="rect-cube rcg">
</div>
</div>
</div>
我一整天都在想这个问题,不明白两个绿色矩形的中间部分是如何相互连接的。
如果您为我提供一些绝妙的想法,我将非常高兴。
这并不是我想要的最好方法,但这也行。
所以基本上,创建一个 2x2 布局,根据需要设置边框、背景颜色...的样式,然后在其下添加一个假布局。
body {
background-color: #0a0e11;
}
.square-wrapper {
display: grid;
grid-template-columns: 1fr 1fr;
grid-template-rows: 1fr 1fr;
width: 200px;
height: 200px;
border-radius: 20px;
overflow: hidden;
position: relative;
}
.square-wrapper:before {
content: "";
display: block;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
width: 50%;
height: 50%;
background-color: #2be72b;
}
.square-wrapper > [class*="cell"] {
display: flex;
align-items: center;
justify-content: center;
border: 10px solid #2be72b;
border-radius: 20px;
background-color: #2be72b;
position: relative;
}
.square-wrapper .cellA, .square-wrapper .cellD {
background-color: #2e2f31;
border-radius: 20px;
border-color: #0a0e11;
color: white;
}
<div class="square-wrapper">
<div class="cellA">A</div>
<div class="cellB">B</div>
<div class="cellC">C</div>
<div class="cellD">D</div>
</div>