0

The website is designed to have 6 big squares, 3 per row, in a grid layout.

I am trying to make it responsive, so if someone zooms the website would adapt... and it kind of does, but in a bad way.

I want the squares to lay different when zooming; If now they are 3 per row I want them to go 2 per row and finally 1 per row if zooming enough. Instead of that the squares narrow themselves in their width in order to fit.

/*///////////GENERAL//////////*/
* {
  margin: 0px;
  padding: 0px;
  box-sizing: border-box;
}

/*///////////HEADER//////////*/

header {
  text-align: center;
  padding: 10px;
  margin-bottom: 20px;
  border-bottom: 1px solid black;
}

#HeaderContainer {
  max-width: 1334px;
  margin-left: auto;
  margin-right: auto;
  display: grid;
  grid-template-columns: repeat(1, 1fr 2fr 1fr);
  grid-auto-rows: minmax(20px, auto);
}
header > div > p {
  padding: 15px;

  font-size: 20px;
  font-weight: lighter;
  font-family: Helvetica, Arial, Sans-serif;

  grid-column: 2/3;
  max-width: 980px;
}
/*///////////MAINSECTION//////////*/

#MainSectionContainer {
  margin-left: auto;
  margin-right: auto;
  max-width: 1000px;
  background: white;
}

section {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-auto-rows: minmax(150px, auto);
  gap: 10px;
}
.SectionBox {
  min-width: 324px, auto;
  display: grid;
  align-content: center;
  justify-content: center;
  border-radius: 30px;
  border: 2px solid black;
  font-family: Helvetica, Arial, Sans-serif;
}

#photo {
  grid-row: 1/3;
}
#web {
  grid-row: 1/3;
}
#coding {
  grid-row: 1/3;
}
#cv {
  grid-row: 3/5;
}
#about {
  grid-row: 3/5;
}
#contact {
  grid-row: 3/5;
}
<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="MyPortfolio" content="MyPortfolio" />
    <link rel="stylesheet" href="StylesMainPage.css" />
  </head>

  <body>
    <header>
      <div id="HeaderContainer">
        <p>WELCOME TO MY PORTFOLIO</p>
      </div>
    </header>
    <div id="MainSectionContainer">
      <section>
        <p id="photo" class="SectionBox">PHOTOGRAPHY</p>
        <p id="web" class="SectionBox">WEB DESIGN</p>
        <p id="coding" class="SectionBox">CODING</p>
        <p id="cv" class="SectionBox">CURRICULUM VITAE</p>
        <p id="about" class="SectionBox">ABOUT ME</p>
        <p id="contact" class="SectionBox">CONTACT</p>
      </section>
    </div>
  </body>
</html>
Penny Liu
  • 15,447
  • 5
  • 79
  • 98
XOG
  • 11
  • 1
  • Maybe you cn inspire yourself from https://stackoverflow.com/questions/58897450/css-grid-with-top-bar-sidebar-and-repeating-content/58900281#58900281 it's made around : `repeat(auto-fit,XX)` – G-Cyrillus May 27 '20 at 09:10
  • Thanks! I will take a look right now! – XOG May 27 '20 at 09:16

1 Answers1

0

You might need auto-fit and auto-flow

Possible example below,

or https://codepen.io/gc-nomade/pen/mdeYpWK with a max numbers of columns set to 3

/*///////////GENERAL//////////*/
*{
    margin: 0px;
    padding: 0px;
    box-sizing: border-box ;
}

/*///////////HEADER//////////*/

header{
    text-align: center;
    padding: 10px;
    margin-bottom: 20px;
    border-bottom:1px solid black;
    
    
}

#HeaderContainer{

    max-width: 1334px;
    margin-left: auto;
    margin-right: auto;
    display: grid;
    grid-template-columns: repeat(1, 1fr 2fr 1fr);
    grid-auto-rows: minmax(20px, auto);
    
}
header > div > p {

    padding: 15px;

    font-size: 20px;
    font-weight: lighter;
    font-family: Helvetica, Arial, Sans-serif;

    grid-column: 2/3; 
    max-width: 980px;
    
}
/*///////////MAINSECTION//////////*/

#MainSectionContainer{
    margin-left: auto;
    margin-right: auto;
    max-width: 1000px;
    background: white;
}

section{
    display: grid;
    grid-template-columns: repeat(auto-fit,minmax(200px,1fr));
    grid-auto-rows: minmax(150px, auto);
    gap: 10px;  
}
.SectionBox{
    min-width: 324px, auto;
    display: grid;
    align-content: center;
    justify-content: center;
    border-radius: 30px;
    border: 2px solid black;
    font-family: Helvetica, Arial, Sans-serif;
}

#photo{
 
    
}
#web{
 
    
}
#coding{
 
    
}
#cv{
   
   
}
#about{
   
}
#contact{
    
    
}


/* ///////// IE11 alternative ////////////////////////*/
section{   
    display: -ms-grid;
    -ms-grid-columns:1fr 10px  1fr 10px  1fr;
    -ms-grid-rows: auto 10px  auto;
}
.SectionBox{
    min-height:150px;
    display: -ms-flexbox;
    flex-direction:column;
    align-items:center;
}


#photo{
    -ms-grid-row: 1;
    -ms-grid-column: 1;    
}
#web{
    -ms-grid-row: 1;
    -ms-grid-column: 3;    
}
#coding{
    -ms-grid-row: 1;
    -ms-grid-column: 5;    
}
#cv{
    -ms-grid-row: 3;
    -ms-grid-column: 1;   
}
#about{
    -ms-grid-row: 3;
    -ms-grid-column: 3;    
}
#contact{
    -ms-grid-row: 3;
    -ms-grid-column: 5;    
}
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="MyPortfolio" content="MyPortfolio">
    <link rel="stylesheet" href="StylesMainPage.css">

</head>

<body>
    <header>
        <div id="HeaderContainer">
            <p>WELCOME TO MY PORTFOLIO</p>
        </div>
    </header>
    <div id="MainSectionContainer">
        
        <section>
           <p id="photo" class="SectionBox">PHOTOGRAPHY</p>
           <p id="web" class="SectionBox">WEB DESIGN</p>
           <p id="coding" class="SectionBox">CODING</p>
           <p id="cv" class="SectionBox">CURRICULUM VITAE</p>
           <p id="about" class="SectionBox">ABOUT ME</p>
           <p id="contact" class="SectionBox">CONTACT</p>


        </section>
    </div>
</body>
    
</html>

jsbin for IE11 testing : https://jsbin.com/sifozaduso/1/edit?css,output

G-Cyrillus
  • 101,410
  • 14
  • 105
  • 129
  • So, auto-fit just adds or substracts number of columns when zooming in or out and fits the content in the available columns, right? Thanks for this solution! – XOG May 27 '20 at 09:23
  • @XOG Yes, you can also set min-width for the column. If you want at the max 3 columns. /-/ Here is an example with 1000px/3 from your design (turned into CSS var to easily update max-width) https://codepen.io/gc-nomade/pen/mdeYpWK /-/ Beware For IE11, it will not work. it requires to set each children into a grid cell, like you initially did. \-\ Possible alternative https://jsbin.com/sozogiruhu/1/edit?css,output – G-Cyrillus May 27 '20 at 09:58
  • thank you so much! I will check what you sent me and see hhow do I apply it well :) – XOG May 27 '20 at 10:20