HTML CSS examples for CSS Layout:Relative Position
Make a relatively positioned div square with CSS
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <style id="compiled-css" type="text/css"> .FlexEmbed {<!-- www . ja v a 2 s . c o m--> display:block; overflow:hidden; position:relative; } .FlexEmbed-ratio { display:block; padding-bottom:100%; width:100%; } .FlexEmbed-content { bottom:0; height:100%; left:0; position:absolute; top:0; width:100%; } .UserImage { background-size:cover; background-image:url('https://www.java2s.com/style/demo/Google-Chrome.png'); } </style> </head> <body> <div class="FlexEmbed FlexEmbed-ratio"> <div class="UserImage FlexEmbed-content"></div> </div> </body> </html>