Search code examples
cssbackgroundbackground-imagebackground-color

Is there a way to layer colors and SVG to make a background


Is it possible to have a background color, then have a SVG file in front of that then another layer with opacity in front of that? Im trying to do a cool effect for the background of a website. Thanks in advance!


Solution

  • You could play around with z-index for that. This should work, a live example is at https://codepen.io/tixpro/pen/VwadJxo

    <body class='main'>
      Hello
      <img src="https://upload.wikimedia.org/wikipedia/commons/1/17/Yin_yang.svg" />
      <div class='overlay'></div>
    </body>
    
    <style>
      body{
       background-color:#424242;
       background-size: 'cover'
    }
     
    /*overlay styling, source: https://www.w3schools.com/howto/howto_css_overlay.asp */
    .overlay{
      position: fixed; /* Sit on top of the page content */
      width: 100%; /* Full width (cover the whole page) */
      height: 100%; /* Full height (cover the whole page) */
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      background-color: rgba(4,0,0,0.5); /* Black background with opacity */
      z-index: 2;
    }
    </style>