Day 21: Grids 3, 4.

 


.item1 {

  grid-row-start: 1;

  grid-row-end: 3;

}

</style>

</head>

<body>


<h1>Grid Lines</h1>


<div class="grid-container">

  <div class="item1">1</div>

  <div class="item2">2</div>

  <div class="item3">3</div>  

  <div class="item4">4</div>

  <div class="item5">5</div>

  <div class="item6">6</div>

  <div class="item7">7</div>

  <div class="item8">8</div>  

</div>

-----------------------------------------------------------------------------------------------------------------------------

1. CSS grid-template-columns Property :

  • By clicking or hovering over the "grid" button on the grid container element in Inspect element, it is simple to visualize grid configurations. The grid layout is now simple to picture.
  • The number (and widths) of columns in a grid layout are specified by the grid-template-columns property.
  • Each value in the values list, which is separated by spaces, indicates the size of the corresponding column.
  • For additional information on the grid-template-columns property, click the following link 

          https://developer.mozilla.org/en-US/docs/Web/CSS/grid-template-columns

  • When an HTML element's display attribute is set to grid or Inline-grid, it transforms into a grid container.
  • By adding display: grid or display: inline-grid to an element, we may construct a grid container. All of that element's direct children turn into grid objects as soon as we do this.
  • To define the start and end of a grid row we can use the following syntax:
      • grid-row : grid row starting number / grid row ending number 

 

  • Example : grid-row : 1/2, will make the item start from column-line 1 and end at column-line 2
  • To define the start and end of a grid column we can use the following syntax:
      • grid-column : grid column starting number / grid column ending number
  • Example : grid-column : 1/3, will make the item start from column-line 1 and end at column-line 3.

 

 

  • Example :
  • Code :

 

<!DOCTYPE html>

<html>

<head>

<style>

    .container {

    displayinline-grid;

    grid-template-columnsauto auto auto;

    background-colorrgb(220165165);

    padding10px;

    }

   

    .item {

    background-colorrgba(2552552550.8);

    border1px dashed rgba(631872000.8);

    text-aligncenter;

    padding20px;

    font-size30px;

    }

    .item4 {

        background-colorblueviolet;

        grid-column1/3;

    }

   

</style>

</head>

<body>

 

<div class="container">

<div class="item item1">grid item 1</div>

<div class="item item2">grid item 2</div>

<div class="item item3">grid item 3</div>  

<div class="item item4">grid item 4</div>

<div class="item item5">grid item 5</div>

</div>

 

</body>

</html>

 

 

Output :

 

       

 

       

 

  • Inline Grid :

 

    <!DOCTYPE html>

    <html>

    <head>

    <style>

        .container {

        displayinline-grid;

        grid-template-columnsauto auto auto;

        background-colorrgb(220165165);

        padding10px;

        }

       

        .item {

        background-colorrgba(2552552550.8);

        border1px dashed rgba(631872000.8);

        text-aligncenter;

        padding20px;

        font-size30px;

        }

    </style>

    </head>

    <body>

   

    <div class="container">

    <div class="item">grid item 1</div>

    <div class="item">grid item 2</div>

    <div class="item">grid item 3</div>  

    <div class="item">grid item 4</div>

    <div class="item">grid item 5</div>

    <div class="item">grid item 6</div>  

    <div class="item">grid item 7</div>

    <div class="item">grid item 8</div>

    <div class="item">grid item 9</div>  

    </div>

   

    </body>

    </html>

 

 

 

Output : 

 

  • Difference between grid and inline-grid :
  • Inline-grid will make the element inline, whereas grid will make it a block-level element. This is the difference between normal grid and inline-grid.

 

  • fr unit :

  By setting the size of a track as a fraction of the available space in the grid container, you can design flexible grid tracks using this non-negative value      given in fr units.

Take a 1000px wide, three-column grid container as an illustration. Consider a layout in which the first (left) column's width is fixed at 200 pixels, the second column occupies one fractional unit, and the third column weighs in at two fractional units:

  • Syntax :

grid-template-columns: 200px 1fr 2fr;



  • repeat() :

The repeat() function is useful  when all the columns are identical.The function takes the number of columns, followed by the column size.

  • Example :

grid-template-columns: repeat(5, 1fr);

Comments

Popular posts from this blog

else-if condition in if-else statements: Concatenation in JavaScript :

Day 9: CSS - Font Formate

Day 28: CSS Animation, CSS Transition Animation Box size