csscss-positionoverlayrectangles

CSS cube overlay


overlay

Hi there, to reproduce this

: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>

I have been thinking of this all day, cannot figure out how the middle part of two green rectangles connect to each other.

I would be more than glad if u offer me some brilliant ideas.


Solution

  • Not really the best way i would have like, but this will work too.

    So basically, create a 2x2 layout, style it as you like with border, background-color... and then add a fake layer under it to fill the gap with matching color of one of the matching opposite cubs.

    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>