Use opacity on a background image without effecting the text - HTML CSS CSS Widget

HTML CSS examples for CSS Widget:Image Text

Description

Use opacity on a background image without effecting the text

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">
div {<!--   w  ww.ja v  a2  s . com-->
   width:321px;
   height:375px;
   display:block;
   position:relative;
   border:2px solid Chartreuse;
}

div::after {
   content:"";
   background-image:url('https://www.java2s.com/style/demo/Google-Chrome.png');
   background-size:cover;
   background-repeat:no-repeat;
   opacity:0.6;
   top:0;
   left:0;
   bottom:0;
   right:0;
   position:absolute;
   z-index:-2;
}
</style> 
 </head> 
 <body> 
  <div>
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi ullamcorper molesti 
  </div>  
 </body>
</html>

Related Tutorials