Code Cheatsheets
  • Code Cheatsheets
  • Chrome Shortcuts
  • General Debugging
  • Google Advanced
  • GraphQL
  • General Mac Shortcuts
  • markdown
  • Regular Expression
  • Tech to Try
  • Typora Shortcuts
  • All
    • Elm
    • Headless CMS
    • Java
    • Swift
    • Solana
    • Solidity
    • APIS
      • Chatwoot
      • Daily
      • DuckDuckGo
      • Facebook Login
      • Google APIS
      • Intercom
      • Mux
      • OpenAI
      • Reddit API
      • Segment
      • Sendgrid
      • Sentry (Debug In Prod)
      • Spotify
      • Stripe
      • Transloadit
      • Zendesk
    • Bash
      • IO in Bash
      • Kills
      • Makefile
      • awk
      • Bash_Profile
      • Cron
      • Curl
      • Diff
      • Emacs
      • Find
      • general
      • Git
      • Grep
      • man
      • Editing File Metadata
      • Sed
      • Secure File Transfer Protocol
      • SSH
      • Vi
      • zip
      • ZSH
      • installed
        • ASDF
        • Bit
        • ffmpeg
        • Generact
        • Graphite
        • ngrok
        • Node Version Manager
        • Spell
        • Tmux
    • C++
      • ptrs
    • CS_Fundamentals
      • Authentication
      • Comparisons
      • Semaphore
      • Content Security Policy
      • Data Structures
      • Editors Comparison
      • Email
      • Encryption
      • Errors
      • Feature Flags
      • HTTP
      • IDs
      • Language Types
      • Microservices
      • Optimization
      • Password Hashing
      • Real Time Messaging Protocol
      • Real-Time
      • Sorting
      • StoringSecrets
      • Testing
      • WebRTC
      • Webhook
    • README
      • Advanced (Postgres?)
      • Database Desigm
      • Firebase
      • Hosts
      • Code Abstractions
      • General Mongo
      • Mongo Aggregation
      • Opensearch
      • Postgres
      • Setup
      • Redis
      • Tips
      • SQL
        • Aggregate
        • Foreign Key Constraints
        • JOINS
        • Optimizations
        • SQL Lite
    • Dev_Apps
      • Featured Shortcuts
      • Iterm2
      • Matlab/Octave
      • Notion
      • Retool
      • Slack
      • Tableplus
      • vimium
      • Featured Shortcuts
      • Warp
      • Windows Terminal
    • Docker
      • Build and Run
      • Docker-compose
      • Dockerfile
      • Multistage builds
      • Swarm
    • Elixir
      • OTP
      • Config
      • DateTime
      • Erlang
      • Errors
      • File
      • Functions
      • Math
      • Modules
      • Regex
      • Setup
      • Time
      • URI
      • Phoenix
        • Channels
        • Handling Controller Errors
        • Controllers
        • Deployment
        • Default File Structure
        • LiveView
        • Plugs
        • Presence
        • Router
        • Session
        • Setup
        • Testing
        • Phoenix.Token
        • Views
        • Workers
        • Ecto
          • ChangeSets and validations
          • Generators
          • Insert/Update
          • Many to Many
          • Migration
          • Query With Repo
          • Relations
          • Schema
        • packages
          • CorsPlug
          • ExRated
          • Ueberauth
      • Collections
        • Lists(linked)
        • Map
        • Set
        • String
        • Structs
        • Tuples
      • Packages
        • Genstage
        • Geolix
        • json
        • Logger
        • Nanoid
        • Oban
        • Redix
        • Sentry
        • Stripe
        • Swoosh
        • Timex
        • http
          • HTTP
          • HTTPoison
          • Tesla
      • Processes / Concurrency
        • Agent
        • Cron
        • GenServer (Generic Server)
        • Registry
        • Supervisors
        • Tasks
    • README
      • IO
      • JSON
      • assert
      • basics
      • control
      • dep
      • errors
      • files
      • func
      • GoRoutines
      • interfaces
      • math
      • request
      • server
      • structs
      • testing
      • time
      • README
        • arrays
        • maps
        • strings
    • HTML Basics
      • Forms
      • Fun
      • SEO
      • Favicon
      • Images
      • Optimizations
      • Scripts
      • overview
        • Handlesbars
        • jade&pug
        • mustache
    • PHP
      • AMP
      • Hack
      • requests
      • setup
    • Python
      • 2.7v3.5
      • advanced
      • Argparse
      • Async Options
      • Classes
      • Secrets
      • environments
      • Importing
      • JSON
      • Os
      • random
      • re
      • testing
      • Datetime
      • Django
        • Databases
        • Models
        • Router
        • Serializers
        • Setup
        • Views
        • packages
          • Secrets
      • General Iterables
        • Dictionaries
        • fancyDicts
        • Heap
        • List
        • Set
        • Strings
      • Flask
        • Blueprint
        • cli
        • Config
        • Deploying Options
        • flash
        • LoginManager
        • packages
        • Requests/Routing
        • RESPONSES
        • templating
        • packages
          • Cors
          • flask_mongoengine
          • Socket IO
        • Postgres in Flask
          • Flask-Migrate
          • Flask-SQLAlchemy
      • packages
        • AIOHTTP
        • Celery
        • cython
        • Environment Variables
        • Excel
        • Google
        • Jupyter Notebook
        • Langchain
        • matplotlib
        • Numpy
        • Pandas
        • PassLib
        • PIL
        • Python Reddit API Wrapper(PRAW)
        • Prisma*
        • Pydub
        • Pymongo
        • Pyppetter
        • Python Requests
        • SQL Alchemy
        • aws
          • AWS Boto3
          • Dynamo
    • README
      • class
      • collections
      • exceptions
      • functions
      • futures
      • guice
      • loops
      • objects
      • options
      • packages
      • pattern&conditional
      • performance&style
      • sbt(running)
      • Strings
      • subtyping
      • traits
  • CSS
    • Obscure
    • Animations
    • Background
    • border
    • colors
    • cursors
    • display
    • Fonts
    • gradients
    • Lists
    • Media Queries
    • Object-fit
    • Overflow
    • pseudoElements
    • Selectors Master Race
    • Transforms
    • Transitions
    • extras
      • Scss
    • Placing Common Tasks
      • HTML Content Box
      • columns
      • Flexbox
      • Grid
      • Position
      • tables
    • Tailwind
      • Animation
      • general
      • Media Queries
      • position
      • Setup
      • Size and Spacing
      • Text
  • Deployment Solutions
    • DNS
    • Digital Ocean
    • Cloudflare
    • Heroku
    • loadtesting
    • Nginx
    • Process Management
    • Redis
    • Socket Alternatives
    • Speed Optimizations
    • {Surge
    • Task Queues
    • Terraform
    • Vercel
    • AWS
      • Certificate Manager
      • Amplify
      • \Cloudfront
      • Cloudwatch
      • Codebuild
      • Codedeploy
      • Code Pipeline
      • Docker in AWS
      • EB
      • ELB (Elastic Load Balancing)
      • IAM roles
      • AWS Lambda (Serverless)
      • Simple Email Service
      • Simple Queue Service
      • Virtual Private Cloud (VPC)
      • Serverless
      • Zappa
      • EC2
        • Scripts
        • Types of EC2
        • EC2(Elastic Compute)
      • Storage
        • Aurora
        • Autoscaling
        • CustomEC2
        • DynamoDB
        • RDS(Relational DB Service)
        • S3(Simple Storage Service)
    • Cloud GPUS
      • Beam
      • Paperspace
      • Replicate
    • Google Cloud Platform
      • Compute
      • Network
    • Github
    • Render
  • Javascript
    • Async and Await
    • Closure
    • Dates
    • Debugging
    • Errors
    • ES6 Specific Features
    • Functions
    • Importing
    • Promises
    • regex
    • Making a request
    • Timeout
    • All
      • Bun
      • Angular
        • HTML
        • HTTP
        • bash
        • input
        • observable_Subject
        • router
        • typescript
      • Chrome Plugins
        • Browser Action
        • Config
        • Content Scripts
        • Context Menu
        • Deploying
        • Desktop Capture
        • Events
        • To Get Identity
        • Manifest
        • Messages
        • Notifications
        • Popup
        • Service Workers
        • Setup
        • Shortcuts / Commands
        • Chrome Storage
        • Tabs
        • Match Patterns
      • Electron
        • Deep Links
        • Deploying
        • Desktop Captuer
        • Dialog
        • Images
        • Menu
        • Messages
        • Differences Between Platforms
        • notarizing
        • Notifications
        • Renderer Process
        • screen
        • Storage Options
        • Tray
        • Windows
        • Electron Packages
          • Electron builder
          • Electron-is-Dev
          • Electron-Log
          • electron-store
          • Electron-Forge
          • Sentry
      • Node
        • Routing
        • ejs
        • Env
        • Errors in Express
        • Files*
        • Forms
        • Logging
        • Middleware
        • Req
        • require
        • Response
        • Setup for Nodejs/Express
        • db
          • Mongoose
          • IoRedis
          • Knex
          • MongoDB
          • Prisma
        • Packages
          • Commander
          • Config
          • Crypto
          • Dotenv
          • Grant
          • Helmet
          • Http-errors
          • Essential Middleware
          • Passport
          • puppeteer
          • Expressjs/session
    • bundlers
      • Parcel
      • Vite
      • Webpack
    • Collections
      • JSON
      • Array
      • Blob (Binary Large Object)
      • Classes
      • Map
      • Objects
      • Set
      • Strings
    • Packages
      • AI
      • AWS SDK
      • Babel
      • Bcrypt
      • Cheerio
      • Concurrently
      • Csv
      • Cypress
      • Eslint
      • Jest
      • Lodash
      • Matter
      • Monaco Editor
      • Use to compile SCSS
      • Prettier
      • Query-string
      • Socket.io
      • Supabase
      • Trpc
      • Zod
    • TypeScript
      • 3rd Party Types
      • Classes
      • Enum
      • Generics
      • Interfaces
      • Migration
      • Narrowing Types
      • Types
      • Utility Types
    • JS In the Browser
      • CORS
      • DOM Control
      • Shadow DOM
      • Audio
      • Canvas
      • Clipboard
      • Cookies?
      • Events
      • Iframe
      • Intersection Observers
      • Keyboard Input
      • Media
      • Navigator
      • Scroll
      • Serving an index.html
      • Storage
      • Web Workers
      • packages
        • Tabulator
        • Bowser
        • Boxicons
        • d3
        • mapbox
        • MouseTrap Key Bindings
        • Videojs
  • ML
    • ML BuzzWords Guide
    • Regularization
    • DataSets
    • Embedding
    • Vector Store
    • Deploy
      • Beam Cloud
      • Paperspace
    • NLP
      • Pre-processing text
      • 2vectorizing
      • 3featureengineering
      • 4ml
      • 4ml2
      • Overview
      • nltk
    • basics
      • Datasets
      • GPU Optimization
      • Neural Nets
  • README
    • Images, Fonts, and Files
    • Children
    • Context
    • Deployment
    • useEffect
    • Errors in React
    • Events
    • Forms
    • Hooks
    • JSX
    • Lists
    • Optimization
    • Rendering
    • Server Components
    • Setting up React
    • State and Lifecycle
    • Style
    • Suspense
    • Next
      • Image
      • Route Handlers
      • App Router
      • Assets
      • Next Config
      • CSS
      • Deploying
      • Layouts
      • Adding Markdown
      • Metadata
      • App Router
      • Server Actions
      • Setup
      • PreAppRouter
        • SSR
        • Api Routes
        • Head
        • Layouts
        • Pages
      • packages
        • ContentLayer
        • MDX Enchanced
        • T3 Env
    • How to fetch Data
      • React Query
    • packages
      • SWR
      • Classnames
      • Color
      • DatePicker
      • Draggable
      • Emotion
      • React-Feather
      • Fluxible
      • General
      • Google Login
      • Intersection Observer
      • React Lazy Load
      • Script
      • Proptypes
      • React Router v6
      • Recharts
      • React-Select
      • ShadCn
      • Slate
      • React-Table
      • Tanstack Router
      • Telephone Input
      • Three-Fiber
      • React-Toastify
      • React-Tooltip
      • React Video JS
      • Waypoint
      • React-window
      • XState
    • How to manage state in React
      • Jotai
      • Mobx
      • Zustand
      • Redux
        • Immer
        • Middleware
        • Redux
        • Redux
        • Redux Toolkit
        • selectors
        • Setup
        • Thunk
    • All
      • Gatsby
        • Cli
        • Data Integrations
        • Link
        • Pages
        • Plugins
        • Setup
        • Style
        • Transformer
        • packages
          • MDX
          • TailwindCss
      • Prehooks
        • Class Components
        • Ref
        • State and Lifecycle
      • React Native
        • ListViews
        • SafeArea
        • Built-in Components
        • Networking
        • Gestures
        • Navigation
        • Notifications
        • Orientation
        • Style
        • Dimensions
        • Expo
          • Development Build
          • Env
          • Setup
        • packages
          • Reanimated
          • React Native View Shot
  • Rust
    • Error
    • Importing
    • Ownership
Powered by GitBook
On this page
  • Basic
  • Comparison to Grid
  • Vocab
  • Setting Up the Grid
  • Properties on Parent
  • Creation
  • Grid-template-Columns & rows
  • Gutters
  • Positioning
  • grid-template-areas
  • Alignment
  • Justify-Items
  • Align-Items
  • PlaceItems:
  • Justify & Align Content
  • Grid-auto-**
  1. CSS
  2. Placing Common Tasks

Grid

Basic

CSS

.app {
  display: grid;
  grid-template-columns: 1fr 2fr 1fr;
  grid-template-rows: 4em 1fr 1fr 1fr 4em;
  grid-template-areas:
    "header header header"
    ". top ."
    ". main ."
    ". bottom ."
    ". . .";
  width: 100vw;
  height: 100vh;
}

/* Give every child element its grid name */
.header {
  grid-area: header;
  background-color: white;
  box-shadow: 0px 0.5px 2px rgba(0, 0, 0, 0.05);
}

.main {
  grid-area: main;
  background-color: gray;
  display: flex;
  justify-content: center;
  align-items: center;
}

.top {
  grid-area: top;
}

.bottom {
  grid-area: bottom;
}

HTML

<div className="app">
  <div className="header">
    <div> Header </div>
  </div>
  <div className="top">Top</div>
  <div className="main">
    <div> Dashboard </div>
  </div>
  <div className="bottom">Bottom</div>
</div>

Comparison to Grid

Flexbox is 2D layout, all the rows are independent, would be hacky if you want all the elements in each row to line up

Basically in every browser now

Grid also much more powerful and can specify an item can take up more rows/columns across multi rows/columns

i.e in flex box

1 | 2 | 3

4 | 5 | 6

7 | 8

Vs. grid

1 | 2 | 3

4 | 5 | 6

7 | 8

Vocab

  • Grid lines: line at left and right of grid and between each row, so 3*3 has 4 horizontal grid lines & 4 vertical grid lines; 1-4

  • Grid cell: any cell

  • Gutter: Grid Gap

  • Grid Track: Either row or col

Setting Up the Grid

Properties on Parent

  • display

  • grid-template-columsn

  • Grid-template-rows

  • Grid-template-areas

  • grid-template(shorthand)

  • Grid-column-gap

  • Grid-row-gap

  • Grid-gap

  • Justify-items

  • align-items

  • justify-content

  • align-content

  • grid-auto-columns: none | |

  • grid-auto-rows: none | |

  • grid-auto-flow

  • Grid

Track List is that 1fr 1fr 1fr 1fr thing

Creation

Default is one cell on each row, all children of display grid are grid elements

div {
    display: grid | inline-grid; 
    // inline-grid just how long it needs to be, basically width: auto according to content
}
ol {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    list-style-type: none;
}

repeat(4, 1fr) == 1fr 1fr 1fr 1fr : gives 4 columns and give every item 1 unit of free space(fraction unit)

Grid-template-Columns & rows

grid-template-columns: 
    150px 150px 150px;
    repeat(3, 8em);
    100px repeat(2, 1 fr) 2fr;
    2fr 125px minmax(300px, 3fr);

Values

  • length or percentage

  • flex: fr

  • max-content

  • min-content

  • minmax(min, max)

  • auto

  • Fit-content

Number of entries is number or rows/columns; mix units at will

Row is the dynamic one that often goes beyond/under the expected amount

Use auto if you want it to fill up available space(like if you want articles to be their size and footer to be small)

Naming Grid Lines

Grid-template-columns: [start] 150px 150px 150px [end];

Basically putting brackets between col width definitions

Can then use these names in propereties like grid-area

ol {
    Grid-template-columns: [start] 150px 150px 150px [end];
}

.myItem {
    grid-area: 2 / start/ 4 / mid;
}

Can use the same name multiple times, then the closest gridline is used(start every 3rd and does closest)

Gutters

  • Grid-column-gap: between each col

  • grid-row-gap: between each row

  • grid-gap(shorthand): ; or ;

Only a single size for each axis, margin/padding still works for each list element and change entire grid layout

Positioning

To place item, say where grid-line starts and which gridline it ends

If you want empty grid boxes, position everything

.myItem {
    grid-row-start: 2;
    grid-row-end: 4;
    grid-column-start: 2;
    grid-column-end: 5;
}
.myItem {
    grid-row: 2 / 4;
    grid-column: 2 / 5; 
    /*could also do 5 / 2 
    2 would be 1 col wide*/
}
.myItem {
    grid-area: 2 / 2 / 4 / 5;
    /*grid-row-start / grid-col-start / grid-row-end / grid-col-end*/
}

grid-template-areas

Describe grid with named areas instead of numbers

body {
    "header header header"
    "nav article aside"
    "footer footer footer"
}

header {
    grid-area: header;
}

nav {
    grid-area: nav;
}
/*etc....*/

Alignment

Parent

  • justify-items

  • align-items

  • justify-content

  • align-content

  • grid-auto-columns

  • grid-auto-rows

  • Grid-auto-flow: shorthand of two above

  • grid

Item

  • justify-self

  • Align-self

Justify-Items

legacy | safe | unsafe| same as flexbox too i.e left| center| flex-start

  • align items in inline direction(horizontal), along columns

  • Safe: if it overflows still show

  • Unsafe: even if overflows, listens to grid

Align-Items

Align along row track, vertical alignment

PlaceItems:

Justify & Align Content

  • Only matters if you have extra space within grid

  • Same values as flex-box, aligns entire rows and columns within grander grid

  • Align again is row spacing, justify is col spacing

Grid-auto-**

grid-auto-columns: 100px;

Any col that is added is 100px

Advanced

If you use 1fr, content that is too big will make the content bigger than the grid. Use minmax(0, 1fr) instead, something about how the min and max are both 1fr which is auto so content size.

PreviousFlexboxNextPosition

Last updated 4 years ago