Flexible grids Flashcards
Before RWD, what was a dominant approach to website structure?
Thinking in fixed proportions. Elements had a certain size and did not adjust if the viewport changed?
What do we mean by viewport?
The size of browser window (generally measured in pixels)
How would we mark up the body element to center it on the page and set its width to 960 pixels?
We’ll write a CSS rule
body {
width: 960px;
margin: 0 auto;
}
Is there anything wrong with setting type in pixels?
No.
What it does mean is type is set at a size and cannot be adjusted by the user.
What’s the formula for calculating proportions
target / context = result
So taking formula how would we translate a 24pt headline into a relative value?
Take the default text size for the browser (probably 16px)
take the value of the headline and divide it by 16
24 / 16 = 1.5
We then assign 1.5em as the text size for our headline.
We use ems as these are proportional unit that will resize with a different sized viewport.
Say we have the following
<h1>Get more spuds<a>click here!</a></h1>
Assume a default font-size of 16px.
Say we know we want our h1 to be 24px and our link to be 11px. If we wanted to express this as ems what.
Why is that?
The context chnages. We talking about a link inside a header tag. Not just a link by itself.
11 / 24 = 0.45833333333
so a {
font-size: 0.4583333333em;
}
You’ll sometimes need to decide how wide the body of a page will be as a percentage? Say we have body tha’s 960px wide. How do we decide how wide that should be in %?
Ethan recommends testing out options and then. There’s not really a set recommendation.
When calculating width of elements and expressing in proportional terms what units should we use?
Use % for size of block level elements (e.g. div, html5 structural elements)
What would be the problem with fixed margins and padding in a flexible layout?
At different viewport sizes, the padding and margins won’t adjust breaking our layout.
With box / block elements we’ll specify the measurement in % using the target/conext=result formula.
The context is always the elements containing element.
Can we have negative proportional margins and padding?
Yes, You sure can!