Use Pseudo Element to Create Background Overlay - HTML CSS CSS Property

HTML CSS examples for CSS Property:background

Description

Use Pseudo Element to Create Background Overlay

Demo Code

ResultView the demo in separate window

<html>
 <head> 
  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  <style id="compiled-css" type="text/css">

.container {<!-- www.  j  a v a  2s .  co m-->
   background-color: red;
   width: 500px;
   height: 500px;
   position: relative;
}
.content {
   background-color: blue;
   width: 250px;
   position: relative;
   z-index: 1;
}
.container::before {
   content:"";
   display: block;
   height: 100%;
   position: absolute;
   top: 0;
   left: 0;
   width: 100%;
   z-index: 1;
   background-color: rgba(255, 255, 255, .8);
}


      </style> 
 </head> 
 <body> 
  <div class="container"> 
   <div class="content"> 
    <h1>Hello, World</h1> 
   </div> 
  </div>  
 </body>
</html>

Related Tutorials