💻
Cheatsheets
  • Most Useful Command Line Tools: 50 Cool Tools to Improve Your Workflow, Boost Productivity, and More
  • 7_tips_to_reverse_engineer_javascript
  • Configuring a Repl
  • How to create your command-line program (CLI) with NodeJS and Commander.js | by Duc N. | JavaScript
  • replit Node.JS 24/7 Project Hoster
  • cheatsheets
  • Alacritty, Tmux, and Vim
  • amethyst
  • Android
  • Installing Arch Linux
  • Arch Linux
  • aria2
  • bin
  • bspwm
  • Chocolately Notes
  • command_line_pipes
  • CSS Grid
  • curl
  • The curl guide to HTTP requests
  • Docker
  • Easymotion
  • Emmet
  • Favorite figlet fonts
  • FFMPEG
  • figlet
  • File Serve
  • File Transfer
  • fish shell
  • Front End Dev Links
  • How to use Git.io to shorten GitHub URLs and create vanity URLs
  • Git
  • Downloading a Tarball from GitHub
  • Make Infinite Gmail Addresses For One Inbox
  • How To Use GPG on the Command Line
  • guide_to_fish_completions
  • Homebrew
  • How to clean Arch Linux
  • HTML5 Boilerplate
  • Install
  • All the keyboard shortcuts you’ll ever need for Safari on iPad
  • iosevka
  • iPhone
  • ish (iOS)
  • Javascript Notes
  • jq
  • Jupyter Notebooks
  • Lettering
  • lf-wiki
  • lf
  • Command Line
  • Adding a swapfile after a clean installation without swap partition
  • mac_bluetooth_issues
  • Mac Terminal
  • maim
  • markdown-sample
  • Markdown Notes
  • Images in README.md Markdown Files
  • Organizing information with tables
  • md_cheatsheet
  • NiftyWindows Help
  • nix
  • Justin Restivo - A Portable Text Editor: Nix <3 Neovim
  • NPM
  • neovim configuration
  • Pastery
  • Powershell
  • Table of Basic PowerShell Commands | Scripting Blog
  • Powershell Modules
  • Puppeteer
  • Python
  • rclone-colab
  • replit
  • Hi there, I'm Raju Ghorai - a.k.a. [coderj001]
  • Scriptable
  • Servor
  • Replacing Postlight’s Mercury scraping service with your self-hosted copy
  • Shell Scripts
  • skhd
  • Spicetify
  • SSH
  • SurfingKeys
  • tar
  • Terminal Web Browser Docker
  • Text Generators
  • tmux shortcuts & cheatsheet
  • unicode
  • VIM
  • VIM Diff
  • vi Complete Key Binding List
  • 8 Essential Vim Editor Navigation Fundamentals
  • Vim Shortcut Keys
  • Vite
  • VNC
  • web-servers
  • Web Server
  • Windows Command Line
  • Writeguard
  • WSL Cheatsheet
  • youtube-dl
  • zsh Plugins
  • zspotify
Powered by GitBook
On this page
  • .grid-container
  • grid-template-columns
  • grid-template-rows
  • justify-items
  • align-items
  • gap is the gap between grid items
  • Grid Items
  • grid-column

Was this helpful?

CSS Grid

.grid-container

The main class container

display: grid is the main property needed here

grid-template-columns

layout of columns horizontally

grid-template-columns: 1fr 1fr 1fr has 3 columns, each one is 1fr

A shorthand would be grid-template-columns: repeat(3, 1fr);

grid-template-rows

is the same as grid-template-columns only vertically

justify-items

How grid pieces are aligned horizontally

justify-items: strech; is default and takes up full width of the columns justify-items: center; centers grid items justify-items: start; pushes grid items to the left justify-items: end; pushes grid items to the right

IMPORTANT

To justify individual grid items, you must use justify-self

justify-self: end; will align grid item to the bottom of it's grid area

align-items

Like justify-items but vertical

IMPORTANT

align-self for vertical alignment of grid items

gap is the gap between grid items

gap: 10px;


Grid Items

grid-column

Helps lay out the grid

grid-column: 1 / span 2; will make this grid item 1 column and span 2 column spaces

See image and code below


<body>
  <div class="grid-container">
    <div>1</div>
    <div>2</div>
    <div>3</div>
    <div>4</div>
    <div>5</div>
    <div>6</div> 
  </div>
body {
 margin: 30px;
 font-family: "Poppins";
}

.grid-container {
 background: #eee;
 max-width: 900px;
 margin: 0 auto;
 display: grid;
 grid-template-columns: repeat(6, 1fr);
 grid-template-rows: 100px 200px 300px;
 gap: 10px;
 justify-items: strech;
 align-items: strech;
}

.grid-container > div {
 background: #ccc;
 text-align: center;
 padding: 20px;
 border: 1px solid #000;
}

.grid-container > div:nth-child(1) {
 grid-column: 1 / span 2;
}
.grid-container > div:nth-child(2) {
 grid-column: 3 / span 3;
}
.grid-container > div:nth-child(3) {
 grid-column: span 1;
}
.grid-container > div:nth-child(4) {
 grid-column: 2 / 6; 
 align-self: end;
}
.grid-container > div:nth-child(5) {
 grid-column: span 3; 
}
.grid-container > div:nth-child(6) {
 grid-column: span 3; 
 justify-self: end;
 align-self: start;
}
Previouscommand_line_pipesNextcurl

Last updated 2 years ago

Was this helpful?

css grid