• Skip to primary navigation
  • Skip to main content
  • Skip to footer

She's Gotta Develop It.com

Notes on web development and programming

  • About
  • Blog
  • Projects
  • code snippets

~/notes | Saturday // December 8, 2018

Notes on CSS Grid Garden

Trying out the new CSS Grid feature!

CSS Grid CSS Grid Garden

0

I originally took this course back in May 2017 but for some weird reason, never published my notes, which I found while attempting to empty my drafts. Decided to unleash them into the universe. Enjoy!

I originally thought I would design Akudo.Codes using the new CSS Grid features so I wanted to familiarize myself with it. I ended up not using it but I hope to give it a spin soon!

In order to begin familiarizing myself with CSS grid, I thought I’d try the Grid Garden Game.

.mygrid {
grid-column-start: value;
grid-column-end: value;
grid-row-start: value;
grid-row-end: value;
}
/* These accept negative numbers for right to left configuration
They also accept a value of `span [number]` which allows you to span across that dimension.
The span value must always be positive, no negative numbers
*/

Shorthands:
grid-column: start-value/end-value;
grid-row: start-value/end-value;

Grid column and grid row can be used together to cover small or large portions of the page grid

There is also a shorthand for the grid-column & grid-row combinations: grid-area which accepts the four start and end values in this format:

#myGrid {
grid-area: 4/4/3/2;
}
//grid-row-start
//grid-column-start
//grid-row-end
//grid-column-end

When using positive numbers, the end value must not be the item area that you want to end at, but one over.

If a grid item is not explicitly placed, then it will be automatically placed according to the order added. The only way to override this default is using the order property.

To set the dimensions of the grid you can use the following properties:

- grid-template-columns: values;
- grid-template-rows: values;

Example:

#myGrid {
grid-template-columns: 50% 50%; // will render two columns with equal widths of 50%
grid-template-rows: 25% 25% 25% 25%; // will render 4 rows with equal heights of 25%
}

Another example:

#myGrid {
grid-template-columns: 50% 20% 20% 10%; // will render four columns with various widths
grid-template-rows: 25% 25% 25% 25%; // will render 4 rows with equal heights of 25%
}

Instead of constantly declaring the values this way, the CSS Grid spec includes a repeat function that allows you to shorten the syntax to:

#myGrid {
grid-template-columns: repeat(2, 50%); // this is identical to declaring grid-template-columns: 50% 50%;
}

CSS Grid introduces a new unit called the fractional, represented by fr. 1fr represents one share of the available space. So if you have two grid items with dimensions of 1fr and 2fr, that will render as 3 equal shares with the first grid item occupying just 1/3 and the second grid item occupying 2/3. When you mix other units with fr, the columns or rows set with fr will split up the remaining space based on the dimensions.

The shorthand for grid-template-columns and grid-template-rows is grid-template.

Those are my notes from completing the exercises. It does not cover every feature in the CSS Grid specification, but it does give me an idea of what it offers on a high level.

Post navigation

Previous:
This Week in Coding: #011
Next:
Using the mklink command in Windows Ubuntu (WSL)

Reader Interactions

Leave a Comment Cancel reply

Your email address will not be published. Required fields are marked *

Footer

Archives

  • April 2019
  • March 2019
  • January 2019
  • December 2018
  • November 2018
  • June 2017
  • May 2017
  • December 2016
  • August 2016
  • July 2016
  • June 2016
  • May 2016
  • April 2016
  • March 2016

Categories

  • @snippets
  • ~/notes
  • Code Reviews
  • Meetups & Events
  • Starter Packs
  • Weekly Updates
  • What I Learned Series

Github

shesgottadevelopit (shesgottadevelopit)

shesgottadevelopit

shesgottadevelopit
atlanta via chicago
https://shesgottadevelopit.com
Joined on Feb 06, 2016
16 Public Repositories
dev-log
fit-connect-app
global-content-blocks
iheartcode
JS-DC-Lab-01
JS-DC-Lab-02
lemonade-wp
npm-link-dev
nunjucks-starter
pixartJSdeploy
practicalJS-TodoList
sans-static
virtualhost
W3C_HTML5.1x
wamp-vhost
_s
3 Public Gists
Copyright 2023 ❤ She's Gotta Develop It.com