13. CSS Layouts
MSER 521�Fall 2025
1
Outline
2
Outline
3
CSS & Layouts
Layouts are the hardest thing about CSS for many reasons:
4
Layout Tips
Outline
6
CSS Units: Absolute Units
7
Units | Example |
Pixels | width: 300px; |
Points | font-size: 12pt; |
CSS Units: Absolute Units
When you’re defining the dimensions of your containers, you typically want to use relative units (percentages, em, rem, vw / vh) so that your layouts resize and look good on multiple screens.
8
CSS Units: Relative Units
9
Units | Description | Example |
em | Relative to the size of the parent element (2em means 2 times the parent element’s font size). | font-size: 2em; |
rem | Relative to size of the root html element (2rem means 2 times the html element’s font size).. See em v. rem CodePen. | font-size: 2rem; |
fr | “Fractional units” of the available space (within the parent element). | grid-template-columns: 1fr 1fr 40px 20%; |
vw | Relative to 1% of the width of the viewport (size of browser window) | width: 30vw; |
vh | Relative to 1% of the height of the viewport (size of browser window) | width: 10vw; |
% | Relative to the parent element | width: 100%; |
Outline
10
Using Media Queries
Media queries allow you to set CSS style rules based on the type of media and the device dimensions of the viewport. Example:
“Turning On” Media Queries in your HTML
In order to make sure that media queries are honored, you need to include a meta tag in the <head></head> of your html file:
<meta name="viewport" content="width=device-width, initial-scale=1.0">
Practice: 00-media-query
13
Tablet or Mobile
Desktop
Outline
14
CSS Grid Cheatsheet
15
CSS Grid Practice
Desktop
Mobile
16
Browser Inspector Demo
Outline
18
Using Flexbox: Suggested Strategy
Parent Container�Put the display into “flex mode” display: flex and then use the following properties to align the child items:
Child Container
Apply sizing to the child container as needed, using the box model (padding, margin, width, height, border).
20
Flexbox: Practice
Start Lab 4
22