Giter VIP home page Giter VIP logo

css-grid's Introduction

Solutions for css-grid by Wes Bos

Live examples

  1. CSS Grid Fundamentals
  2. Grid Auto-flow
  3. Sizing tracks in CSS Grid
  4. CSS Grid repeat function
  5. Sizing Grid Items
  6. Placing Grid Items
  7. auto-fit and auto-fill
  8. Using minmax() for Responsive Grids
  9. Grid Template Areas:
  10. Naming Lines in CSS Grid
  11. grid-auto-flow dense Block Fitting
  12. CSS Grid Alignment + Centering
  13. Re-ordering Grid Items
  14. Nesting Grid with Album Layouts
  15. CSS Grid Image Gallery
  16. Flexbox vs CSS Grid:
  17. Recreating Codepen
  18. Bootstrappy Grid with CSS Variables
  19. Responsive Website
  20. Full Bleed Blog Layout

CSS Grid Fundamentals

Defines:

  • Gap between grid elements display: grid;
  • Columns width grid-template-columns: 200px 400px; (first column to 200px, second column to 400px)
  • Rows height grid-template-rows: 50px 100px; (first column to 50px, second column to 100px)
  • Remaing rows default height grid-auto-rows: 250px 500px;
.container {
        display: grid;
        grid-gap: 20px;
        grid-template-columns: 200px 400px;
        grid-template-rows: 50px 100px;
        grid-auto-rows: 250px 500px;
      }

Grid Auto-flow

Determines if new elemens will be added as rows (default behaviour) or as columuns

  • Define thw two first columns grid-template-columns: 200px 400px; (first column to 200px, second column to 400px)
  • Add new elements as columns grid-auto-flow: column;
  • Define auto flow columns size grid-auto-columns: 250px
<div class="container">
      <div class="item">1</div>
      <div class="item">2</div>
      <div class="item">auto-flow</div>
      <div class="item">auto-flow</div>
</div>

<style>
.container {
        display: grid;
        grid-gap: 20px;
        grid-template-columns: 200px 400px;
        grid-template-rows: 50px 100px;
        grid-auto-rows: 250px 500px;
      }
</style>

Sizing Tracks in CSS Grid

Fractional unit (fr) represents the amount of space left after all the elemens are laid out, including its margins, paddings and borders.

  • grid-template-columns: 200px 2fr 1fr 2fr; will divide the remaning space of <div= class="container"> after adding a 200px column into 3 other columns, the first one will use 2 fractional units, the second 1 fractional unit and the last 2 fractional units.
.container {
  display: grid;
  grid-gap: 20px;
  border: 10px solid var(--yellow);
  grid-template-columns: 200px 2fr 1fr 2fr;
}

fractional-units

  • For grid-template-rows the default height of an element is just however hight the element is and default width of an element is as wide as the actual view port.
.container {
  display: grid;
  grid-gap: 20px;
  border: 10px solid var(--yellow);
  grid-template-columns: 200px 2fr 1fr 2fr;
}

fractional-units2

  • auto keyword automatcly sizes the column / row to the the wider / highest grid element.

    .container {
      display: grid;
      height: 400px;
      grid-gap: 20px;
      border: 10px solid var(--yellow);
      grid-template-columns: 200px 1fr 1fr auto;
    }

fractional-units2

CSS Grid repeat function

  • repeat function cuts down the amout of line codes
.container {
        display: grid;
        grid-gap: 20px;
        grid-template-columns: repeat(2, 150px) 2fr repeat(2,100px);
      }

fractional-units2

Sizing Grid Items

  • Grid items by default naturally flows one after another and fit themselves as into the grid as they can.
  • grid-column: span 2 and grid-row: span 2 changes the natural flow of the column/row.

fractional-units2

Placing Grid Items

  • Grid items position and size can be changed either using the abreviation grid-column / grid-row setting where the item should start, end and its size

See 11 - Spanning and Placing Cardio for more examples

  /* Make item 20 start at row 4 and go for 3 */
  .item20 {
    grid-row: 4 / span 3;
  }

css-grid's People

Contributors

nsilverio avatar

Watchers

James Cloos 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.