Giter Club home page Giter Club logo

css-grid's Introduction

CSS Grid

Grid Template Areas

The best way to define element positions in the grid is by using grid-template-areas, since that way the CSS is more readable and it also makes very simple to make changes in the grid.

.container {
  display: grid;
  grid-gap: 15px;
  grid-template-columns: 2fr 2fr 1fr;
  grid-template-rows: 1fr 1fr 1fr 2fr;
  grid-template-areas:
    "b1 b2 b2"
    "b1 b3 b4"
    "b5 b3 b6"
    "b7 b7 b6";
}
.box1 {
  grid-area: b1;
}

.box2 {
  grid-area: b2;
}
...

Click here to see the CSS file

Grid column and Grid Row

Other way to define the position of the elements on the grid is by using grid-column and grid-row, this way is not very readable and is a little bit confusing, but it allows you to make the elements overlap others if it's necessary

With grid-column and grid-row, you need to define the grid line that the element starts and also the line that it ends.

Here's an example with box1, that starts on column 1 and ends at the column 2, and starts on the row 1 and ends at the row 3:

.box1 {
  grid-column: 1/2;
  grid-row: 1/3;
}
.container {
  height: 80%;
  width: 80%;
  display: grid;
  grid-gap: 15px;
  grid-template-columns: 2fr 2fr 1fr;
  grid-template-rows: 1fr 1fr 1fr 2fr;
}

.box1 {
  grid-column: 1/2;
  grid-row: 1/3;
}

.box2 {
  grid-column: 2/4;
  grid-row: 1/2;
}

.box3 {
  grid-column: 2/3;
  grid-row: 2/4;
}
...

Click here to see the CSS file

Overlap example

.box2 {
  grid-column: 2/4;
  grid-row: 1/2;
}

.box4 {
  grid-column: 3/4;
  grid-row: 1/3;
}

Note that box2 starts on row 1 and ends at the row 2, and the box4 starts on row 1 and ends at the row 3

css-grid's People

Contributors

lucassonego avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.