Responsive Layouts using media queries

Responsive Layouts using media queries
0

#1

Completed the challenge but dont understand why i didnt have to write
grid-template-columns: auto 1fr;
grid-template-rows: auto 1fr auto;

or something with different values for the 400px media querie

Thinking now that it might have to do with the fact that i dont have a full understanding of what grid template column and row is doing with those values…

Like the auto 1fr auto; what is this specifying ?
Im almost there :’)

Your code so far


<style>
  .item1 {
    background: LightSkyBlue;
    grid-area: header;
  }
  
  .item2 {
    background: LightSalmon;
    grid-area: advert;
  }
  
  .item3 {
    background: PaleTurquoise;
    grid-area: content;
  }
  
  .item4 {
    background: lightpink;
    grid-area: footer;
  }
  
  .container {
    font-size: 1.5em;
    min-height: 300px;
    width: 100%;
    background: LightGray;
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: 50px auto 1fr auto;
    grid-gap: 10px;
    grid-template-areas:
      "header"
      "advert"
      "content"
      "footer";
  }
  
  @media (min-width: 300px){
    .container{
      grid-template-columns: auto 1fr;
      grid-template-rows: auto 1fr auto;
      grid-template-areas:
        "advert header"
        "advert content"
        "advert footer";
    }
  }
  
  @media (min-width: 400px){
    .container{
      /* change the code below this line */
    
      grid-template-areas:
        "header header"
        "advert content"
        "footer footer";
    
    /* change the code above this line */
    }
  }
</style>
  
<div class="container">
  <div class="item1">header</div>
  <div class="item2">advert</div>
  <div class="item3">content</div>
  <div class="item4">footer</div>
</div>

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:61.0) Gecko/20100101 Firefox/61.0.

Link to the challenge:
https://learn.freecodecamp.org/responsive-web-design/css-grid/use-media-queries-to-create-responsive-layouts


#2

With grid-template-rows/columns, each value you add specifies the size of each new row/column. The more you add, the more rows you have. Auto is auto, and fr is some fraction determined by behind-the-scenes value.


#3

Great thanks,

However i still dont understand why it is not necessary to have the grid template row/columns specified in the 400px min width media querie?

@media (min-width: 300px){
.container{
grid-template-columns: auto 1fr;
grid-template-rows: auto 1fr auto;
grid-template-areas:
“advert header”
“advert content”
“advert footer”;

@media (min-width: 400px){
.container{

  grid-template-areas:
    "header header"
    "advert content"
    "footer footer";

#4

I believe it is not necessary because the grid template from the min-width 300px query still works for 400px width and more