This is my course notes which mainly summarised the best practices in web application layout.
Course Github link: https://github.com/jen4web/fem-layout
Responsive Design Definition
- Flexible grid-based layout
- Media queries (CSS3)
- Images that resize
Float-based Grid System
if you float, you must clear !
1 | .row::after { |
Example: Float-based Grid System Example
Disadvantages
- equal height problem
- hard to do reordering
- impossible to do spacing
Flexbox-based Grid System
Flexbox Introduction
- The first layout elements - but not designed to lay out whole web pages
- Features flex-containers(row) and flex-items(cells). Both are required to work together.
- Excels at vertical centering and no equal heights problem
- very easy to reorder boxes
- Major disadvantages:
- wasn't designed to be locked down for layouts! Works in 1 dimension only (one continuous row, it will wrap on to the next line as it runs out of screen space indefinitely)
- browser support and syntax is challenging
Flexbox Properties Cheatsheet
1 | Flexbox Properties |
Example: * Flex-based Grid System Example 1 * Flex-based Grid System Example 2
Responsive Images
Images shoud change size, based on screen resolution * Load a big image and let it scale (not good) * Server-side (good) * Client-side: load several images and display the one right for this resolution (not good) * Client-side: let js decide (better)
Better Solution: New picture tag released in HTML 5.1 with Picturefill polyfill to ensure backwards compatibiltiy
1 | <picture> |
1 | <head> |
srcset and sizes
the browser decides which image to download
Image downloads and performance
Media Query & Asset Downloading Results > using background in media queries could be a good practice and reduce unnecessary downloads
CSS Grid (TODO)
Some useful CSS tricks
attribute selector documentation The CSS attribute selector matches elements based on the presence or value of a given attribute.
border-box model box-sizing-border-box-ftw
1 | /* apply a natural box layout model to all elements, but allowing components to change */ |
Some useful websites
- https://caniuse.com/flexbox
- http://flexboxgrid.com/