skip to Main Content

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?

2

Answers


  1. For the visible endings at either side, you could make the .flag-strip extra-wide (like 120vw) and instead of starting at left:0 you could start it 20px off the view (i.e. -20px) – see below:

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

    if you do not want any scrollbars, you can also make the .body hide the overflow in both directions (not just X)

     body {
        overflow: hidden;
        margin: 0;
        padding: 0;
     }
    

    See runnable demo:

    html,
    body {
      overflow: hidden;
      margin: 0;
      padding: 0;
    }
    
    body {
      display: flex;
      margin: 0;
      padding: 0;
    }
    
    .flag-strip {
      position: absolute;
      width: 120vw;
      height: 15px;
      left: -20px;
      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>
    Login or Signup to reply.
  2. 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>
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search