Center icon without absolute or relative positioning - HTML CSS CSS Layout

HTML CSS examples for CSS Layout:Relative Position

Description

Center icon without absolute or relative positioning

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">
#lightgallery a {
   width:calc(100% / 4);
   height:241px;
   text-decoration:none;<!--from   w w w  .j av a  2 s  . c  o  m-->
   position:relative;
}

#lightgallery img {
   width:100%;
   background-image:;
   background-repeat:no-repeat;
   height:241px;
   object-fit:cover;
}

#lightgallery {
   display:flex;
   flex-wrap:wrap;
   margin:7.26em 0;
}

a[href*="youtu"]::before {
   font-family:'FontAwesome';
   content:"!";
   font-size:3.6em;
   position:absolute;
   display:flex;
   width:100%;
   height:100%;
   justify-content:center;
   align-items:center;
}
</style> 
 </head> 
 <body> 
  <div id="lightgallery"> 
   <a href="youtu"> <img src="https://www.java2s.com/style/demo/Safari.png" alt=""> </a> 
   <a href="youtu"> <img src="https://www.java2s.com/style/demo/Opera.png" alt=""> </a> 
   <a href="youtu"> <img src="https://www.java2s.com/style/demo/Opera.png" alt=""> </a> 
  </div>  
 </body>
</html>

Related Tutorials