Learn CSS Grid the easy way
Why Stack Overflow recommends it
Stack Overflow users link it when answering layout questions where CSS Grid is the fix, as a friendly introduction to grid for askers new to it.
Recommended by 4 people across 9 different months, 2022 to 2023.
What it is
A 37-minute screencast by Kevin Powell that teaches CSS Grid in a simplified way, covering display grid, gap, columns and rows, spanning, line numbers, media queries, grid-template-areas and auto rows and columns. It follows a hands-on exercise with a GitHub repo and uses the browser's grid inspector.
What people said
Strong rec ramalandajo · 2022-06 · Stack Overflow · on “Aside navigation height to footer, not in fixed position”
Look im NO expert on css or html, but i THINK you could do this with grid. You could set the grod-template-columns to have 2 columns with auto, and 2 rows, and set the footer with a span: 2; on the second row. Poor explanation i know, but you can check out this amazing video by Kevin Powell where he explains grid and grid-template-columns and areas and span, and you will learn a lot. Here is the link, hope it helps: [this video] *I realize as i post this that this post is from 6 years ago, but still maybe it can help someone :D
Strong rec Todd Coulson · 2022-09 · Stack Overflow · on “Aligning responsive "notice board" to the left and a larger "framed main text" area directly to the right”
Thanks a ton for the accepted post. I would also HIGHLY recommend Kevin Powell on Youtube, he is outstanding, this will teach you about grid and css [this video] tons of free videos to get you feeling like an expert.
Recommends Dejan.S · 2022-07 · Stack Overflow · on “How to align section and footer to the left of sidenav?”
Keep it up. I would recommend to learn flexbox [LINK] and grid [LINK] . If you like video content for learning I would recommend two awesome instructors both with great content. For flexbox: Kevin Powells Learn flexbox the easy way [LINK] or Wes Bos flexbox series [LINK] . For grid you can check both Kevin [this video] and Wes [LINK] . Happy learning and good luck :)
Recommends Adam · 2022-09 · Stack Overflow · on “HTML/CSS and Flex : Position and size 3 elements according to rotations”
As Paulie_D points out, grid is definitely the way to go here. Grid allows you to set up the basic layout. You can then set the widths and colours of the elements using css variables. These can be set by simply changing one of the classes in the grid container. I've put a basic skeleton together to show you how this can be done. I recommend reading the css-tricks [LINK] article and watching this [this video] from Kevin Powell too. It's a good primer. Grid has a steep learning curve because there's a lot of options but it's worth the effort and once you know your way around, putting together kickass layouts becomes a lot easier. function doBorder(orientation) { const gridElement = document.querySe
Recommends Adam · 2022-09 · Stack Overflow · on “how can i make dynamic layout using media query?”
I'm late to the party with this one but Grid's the way to go in my opinion as you get complete control over where you put items. It's much more versatile than flexbox but it is a steep learning curve initially as there are so many options. Kevin Powell has a good introductory video [this video] to grid and this [LINK] is also a good, clearly-written resource from css tricks. .container { display: grid; grid-template-columns: 3fr 1fr; grid-template-areas: "a b" "c c"; border: 2px solid #285DBB; row-gap: 0.25rem; column-gap: 2rem; padding: 0.35rem; } .container>div { background-color: #92D050; color: white; display: grid; place-content: center; padding: 0.75rem 2rem; } .zoneA { grid-area: a; text-d
Recommends Adam · 2022-10 · Stack Overflow · on “CSS Flexbox columns are overflowing”
CSS grid is the way to go here. You can use grid-template areas to span cells like the calculator example I've done below. There's a great primer here [LINK] and a good video by Kevin Powell here [this video] I've knocked up an example to get you started. .bottom { display: grid; width: 50%; grid-template-columns: repeat(4, 1fr); grid-template-areas: "b4 b5 b6 bdiv""b1 b2 b3 bequals""bdot b0 bpercent bequals"; gap: 0.5rem; } .bottom>div { /* aspect-ratio: 1; */ background-color: lightgray; display: grid; place-items: center; padding-block:1rem; transition: background-color 0.2s; cursor: pointer; } .bottom>div:hover { background-color:darkgray; } .button-1 { grid-area: b1; } .button-2 { grid-area:
Recommends Adam · 2022-11 · Stack Overflow · on “Padding between elements but not on the sides”
Grid is the way to go here. grid-template-columns tells the browser to have the divs spaced two apart (if you wanted three columns, just have three widths specified - if you want to have several columns the same width you can also use repeat() ). Then use gap to alter the space between. CSS tricks [LINK] has a good primer on grid and Kevin Powell [this video] also has a good intro to it .title-container { padding: 0.5rem 1.5rem; border: 2px solid black; color: red; width: fit-content; } .container { display: grid; width: fit-content; grid-template-columns: 5rem 5rem; gap: 0.5rem; outline: 2px solid red; margin-block: 0.5rem; } .container>div { height: 7rem; border: 2px solid #22B14C; } <div class
Recommends Adam · 2022-11 · Stack Overflow · on “div positioning right under the other inline”
Inline elements can't position themselves like what you want as they're block level elements. You can use CSS grid and set div-2 to span two rows. There's a lot to grid but it's really flexible. Have a look. I've annotated the CSS so you can see how I've done it. Some good resources on CSS tricks [LINK] and here's a video [this video] by Kevin Powell that's a handy introduction. .div-main { border: 5px solid yellow; padding: 15px; /* this makes a grid layout with 2 columns and as many rows as needed. */ /* There's only 3 divs so that'll automatically give us 2 rows */ /* The grid-template-columns property is the width of each column - though there are some qualifications with this */ display: gri
Recommends Adam · 2022-11 · Stack Overflow · on “How to Create Responsive Side by Side Sections in HTML and CSS Only”
Grid is the way to go here as you can use the grid-template-columns to set the width equally. Flexbox will do the same but it need a bit more work, especially if you want to stop your headers wrapping. There's a good introduction to grid from Kevin Powell [this video] and CSS tricks [LINK] also have a good guide. It's very powerful and recommended to learn both flex and grid as they solve a lot of problems from the bad old days. .indent-1 { display: inline-grid; grid-template-columns: 1fr 1fr; border: 2px solid orange; border-radius: 5px; padding-right: 10px; padding-left: 10px; } <section class="indent-1"> <section> <h3>What we like:</h3> <ul> <li>Pro 1</li> <li>Pro 2</li> <li>Pro 3</li> </ul> <
Recommends Adam · 2023-01 · Stack Overflow · on “Would like to have equal widths for my flex item buttons, but not sizing at all”
Replace your flexbox with grid. If you set the grid-template-columns to 1fr then each child will occupy the same size. More info on CSS tricks [LINK] and there's a nice video from Kevin Powell [this video] .icon { background-color: lavender; height: 42px; width: 42px; display: flex; justify-content: center; align-items: center; border-radius: 50%; font-weight: 700; font-size: 26px; color: royalblue; } .prompt { display: flex; flex-direction: column; align-items: center; } .buttonbox { /*replaced flex with grid */ display: grid; grid-template-columns: repeat(2, 1fr); background: lavender; } .button{ border-radius: 5px; } .button.sure { background: royalblue; color: white; /*flex: 1; delete this, n