for the busy developer
Responsive web design (RWD) or responsive design is an approach to web design that aims to make web pages render well on a variety of devices and window or screen sizes from minimum to maximum display size to ensure usability and satisfaction.
– Ethan Marcotte
<html>
<body>
<table>
<tr>
<td colspan="3">Header</td>
</tr>
<tr>
<td rowspan="2"">Navigation</td>
<td>Content</td>
<td rowspan="2">Navigation</td>
</tr>
<tr>
<td>Footer</td>
</tr>
</table>
</body>
</html>
<div class="container">
<div class="row">
<div class="twelve columns">Header</div>
</div>
<div class="row">
<div class="two columns">Nav</div>
<div class="eight columns">
<div class="container">
<div class="row">
<div class="twelve columns">Content</div>
</div>
<div class="row">
<div class="twelve columns">Footer</div>
</div>
</div>
</div>
<div class="two columns">Aside</div>
</div>
</div>
Photo by ThisisEngineering RAEng on Unsplash
If you are having code problems I feel bad for you son.
I got 99 problems but IE ain't one.
body {
display: grid;
gap: 1em;
}
<html>
<body>
<header>Header</header>
<nav>Navigation</nav>
<main>Content</main>
<footer>Footer</footer>
</body>
</html>
body {
display: grid;
gap: 1em;
grid-template-rows: auto auto 1fr auto;
min-height: 100vh;
}
<html>
<body>
<header>Header</header>
<nav>Navigation</nav>
<main>Content</main>
<footer>Footer</footer>
</body>
</html>
body {
display: grid;
gap: 1em;
grid-template-columns: 12em auto;
grid-template-rows: auto 1fr auto;
}
header {
grid-column: span 3;
}
nav {
grid-row: span 2;
}
<html>
<body>
<header>Header</header>
<nav>Navigation</nav>
<main>Content</main>
<footer>Footer</footer>
</body>
</html>
body {
display: grid;
gap: 1em;
grid-template-columns: 12em auto 12em;
grid-template-rows: auto 1fr auto;
}
header {
grid-column: span 3;
}
nav, aside {
grid-row: span 2;
}
<html>
<body>
<header>Header</header>
<nav>Navigation</nav>
<main>Content</main>
<aside>Aside</aside>
<footer>Footer</footer>
</body>
</html>
body {
display: grid;
gap: 1em;
grid-template-columns: 12em auto 12em;
grid-template-rows: auto 1fr auto;
}
header {
grid-column: 1 / 4;
grid-row: 1;
}
nav {
grid-column: 1 / 2;
grid-row: 2 / 4;
}
main {
grid-column: 2 / 3;
grid-row: 2;
}
aside {
grid-column: 3 / 4;
grid-row: 2 / 4;
}
footer {
grid-column: 2 / 3;
grid-row: 3;
}
body {
display: grid;
gap: 1em;
grid-template-columns: 12em auto 12em;
grid-template-rows: auto 1fr auto;
grid-template-areas:
'header header header'
'nav main aside'
'nav footer aside';
}
header { grid-area: header; }
nav { grid-area: nav; }
main { grid-area: main; }
aside { grid-area: aside; }
footer { grid-area: footer; }
Media queries allow you to adapt your site or app depending on the presence of various device characteristics such as:
body {
display: grid;
gap: 1em;
grid-template-rows: auto auto 1fr auto;
grid-template-areas:
'header'
'nav'
'main'
'footer';
}
@media (min-width: 40em) {
body {
grid-template-columns: 12em auto;
grid-template-rows: auto 1fr auto;
grid-template-areas:
'header header'
'nav main'
'nav footer';
}
}
@media (min-width: 60em) {
body {
grid-template-columns: 12em auto 12em;
grid-template-rows: auto 1fr auto;
grid-template-areas:
'header header header'
'nav main aside'
'nav footer aside';
}
aside { display: block; }
}
I don't have a magic formula for selecting breakpoints.
However, I find a good rule of thumb is to select two break points to give your site or app 3 distinct layouts.
You only need to consider them when your design breaks at different screen resolutions.
Just send a large image down the wire and set it's width to 100%. Works everywhere! 👏
Let the browser choose the right sized image for the device.
<img
sizes="
(min-width: 960px) 600px,
(min-width: 640px) 300px,
150px
"
srcset="
css-grid-mobile.png 150w,
css-grid-laptop.png 300w,
css-grid.png 600w
"
src="css-grid.png"
/>
In our simple example downloading the image sized for mobile saves 230 kb.
Used when you want to change more than the resolution of the image you serve.
<picture>
<source srcset="css-grid-night.png"
media="(prefers-color-scheme: dark)">
<img src="css-grid.png">
</picture>
Other options:
For example dark mode:
In recent years we've pivoted towards better developer experience at the expense of the user experience. None of the things we've talked about today require a byte of JavaScript in order to work.
Reducing the amount of JS downloaded/parsed/run will increase the performance of your site/app.
Bias towards web fundamentals before reaching for that JS framework.
Home
About
Contact
nav {
grid-area: nav;
display: flex;
justify-content: space-between;
}
<html>
<body>
<header>Header</header>
<nav>
<p>Home</p>
<p>About</p>
<p>Contact</p>
</nav>
<main>Content</main>
<footer>Footer</footer>
</body>
</html>
@media (min-width: 40em) {
nav {
flex-direction: column;
justify-content: flex-start;
}
}
Home
<html>
<body>
<header>Header</header>
<nav>
<p>Home</p>
<p>About</p>
<p>Contact</p>
</nav>
<main>Content</main>
<footer>Footer</footer>
</body>
</html>
About
Contact