htmlcss

Slanted stripes on a page


I would like some full sized slanted stripes on the page; that's all.

This is what I did so far:

html, body {
    overflow-x: hidden;
    margin: 0;
    padding: 0;
}
body {
    display: flex;
    margin: 0;
    padding: 0;
}

.flag-strip {
    position: absolute;
    width: 100vw;
    height: 15px;
    left: 0;
    transform: rotate(-10deg);
    z-index: 1;
}

.flag-strip.red {
    background-color: #D90012;
    top: 9%;
}

.flag-strip.blue {
    background-color: #0033A0;
    top: 10.5%;
}

.flag-strip.orange {
    background-color: #F2A800;
    top: 12%;
}

@media (max-width: 878px) {
    .flag-strip.red {
        top: 11%;
    }

    .flag-strip.blue {
        top: 12.5%;
    }

    .flag-strip.orange {
        top: 14%;
    }
}
<div class="flag-strip red"></div>
<div class="flag-strip blue"></div>
<div class="flag-strip orange"></div>

But the user shouldn't have a horizontal scroll bar, and the stripes should be really full sized -- there shouldn't be any endings visible on the page.

How can I make it work like that?


Solution

  • You can do this entirely in CSS with linear-gradient as the background.

    html, body {
        margin: 0;
        padding: 0;
        height: 100vh;
    }
    .flag-bg {
        height: 100%;
        
        --flag-a: 10deg;
        --flag-h: 30px;
        --flag-pos: 20%;
        --flag-color1: #D90012;
        --flag-color2: #0033A0;
        --flag-color3: #F2A800;
        --flag-antialias: 1px;
        background-image: linear-gradient(calc(180deg - var(--flag-a)),
          transparent        calc(var(--flag-pos) - var(--flag-antialias)),
          var(--flag-color1) calc(var(--flag-pos)),
          var(--flag-color1) calc(var(--flag-pos) + var(--flag-h) / 3 - var(--flag-antialias)),
          var(--flag-color2) calc(var(--flag-pos) + var(--flag-h) / 3),
          var(--flag-color2) calc(var(--flag-pos) + 2 * var(--flag-h) / 3 - var(--flag-antialias)),
          var(--flag-color3) calc(var(--flag-pos) + 2 * var(--flag-h) / 3),
          var(--flag-color3) calc(var(--flag-pos) + var(--flag-h) - var(--flag-antialias)),
          transparent        calc(var(--flag-pos) + var(--flag-h))
        );
        background-repeat: no-repeat;
    }
    <div class="flag-bg"></div>