CSS grid layout: Keeping horizontal and vertical gutters equal size when resizing - HTML CSS CSS Layout

HTML CSS examples for CSS Layout:Layout

Description

CSS grid layout: Keeping horizontal and vertical gutters equal size when resizing

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">
.wrapper {<!--from   ww w .j a  v  a2 s .  c  o  m-->
   display:grid;
   grid-template-columns:auto;
   grid-template-rows:auto;
   margin:0 auto;
   border:2px solid Chartreuse;
   height:100vh;
   grid-gap:11vmin;
}

.wide {
   display:grid;
   grid-template-columns:100%;
   grid-template-rows:auto 2.26em;
   border:2px dashed yellow;
   grid-gap:11vmin;
}

.composed {
   display:grid;
   grid-template-columns:50.295774648% 2.408450705% 50.295774648%;
   grid-template-rows:auto 2.26em;
   border:2px dashed blue;
}

.composed-a {
   grid-column:2 / 3;
   grid-row:2 / 5;
   background-color:pink;
}

.composed-b {
   grid-column:4 / 5;
   grid-row:2 / 3;
   background-color:OrangeRed;
}

.composed-c {
   grid-column:4 / 5;
   grid-row:4 / 5;
   background-color:grey;
}

figure {
   margin:0;
   padding:0;
}

img {
   max-width:100%;
   height:auto;
   display:block;
   margin-left:auto;
   margin-right:auto;
}

body {
   margin:0;
}

* {
   box-sizing:border-box;
}
</style> 
 </head> 
 <body> 
  <div class="wrapper"> 
   <div class="wide"> 
    <figure class="wide-a"> 
     <img src="https://www.java2s.com/style/demo/Opera.png" width="50" height="50" alt=""> 
    </figure> 
   </div> 
   <div class="composed"> 
    <figure class="composed-a"> 
     <img src="https://www.java2s.com/style/demo/Opera.png" width="50" height="50" alt=""> 
    </figure> 
    <figure class="composed-b"> 
     <img src="https://www.java2s.com/style/demo/Opera.png" width="50" height="50" alt=""> 
    </figure> 
    <figure class="composed-c"> 
     <img src="https://www.java2s.com/style/demo/Google-Chrome.png" width="50" height="50" alt=""> 
    </figure> 
   </div> 
  </div>  
 </body>
</html>

Related Tutorials