Reading notes for Reading 01.
Responsive design is made up of 3 components
Build with flexible grid, which dynamically resizes
Note: relative viewport lengths are new, not fully supported but growing.
Relative measure based on parent width (From Ethan Marcotte). Target width of element / width of parent element.
target ÷ context = result
section,
aside {
margin: 1.858736059%; /* 10px ÷ 538px = .018587361 */
}
section {
float: left;
width: 63.197026%; /* 340px ÷ 538px = .63197026 */
}
aside {
float: right;
width: 29.3680297%; /* 158px ÷ 538px = .293680297 */
}
/* Default styles first then media queries */
@media screen and (min-width: 400px) {...}
@media screen and (min-width: 600px) {...}
@media screen and (min-width: 1000px) {...}
@media screen and (min-width: 1400px) {...}
Responsive CSS, now with Media Queries:
section,
aside {
margin: 1.858736059%;
}
@media all and (min-width: 420px) {
.container {
max-width: 538px;
}
section {
float: left;
width: 63.197026%;
}
aside {
float: right;
width: 29.3680297%;
}
}
viewport
media tag invented by Appleheight
or width
to inherit device defaultinitial-scale
1-10. Set to 1 to equivalent to regular zoom.minimum-scale
/ maximum-scale
- how big or small vp may be scaled. Min must be <= initial-scale
user-scalable
set to no
to diabled scaling. Bad practice for accessibility.<meta name="viewport" content="width=device-width">
<meta name="viewport" content="initial-scale=2">
Will be zoomed in / generally only use 1
Flexible Media#flexible-media allows for pixel by pixel control of scaling. Not common. Accepts:
device-dpi
, high-dpi
, medium-dpi
, low-dpi
<meta name="viewport" content="target-densitydpi=device-dpi">
You can set multiple properties, comma separated.
<meta name="viewport" content="width=device-width, initial-scale=1">
Best practice to define in CSS
@viewport {
width: device-width;
zoom: 1;
}
Media should scale too! Quick and easy:
img, video, canvas {
max-width: 100%;
}
Set
max-width
to 100% scales media with viewport
max-width
wont work on embedded media or iframes. Workaround:
max-width
to 100%HTML
<figure>
<iframe src="https://www.youtube.com/embed/4Fqg43ozz7A"></iframe>
</figure>
CSS
figure {
height: 0;
padding-bottom: 56.25%; /* 16:9 */
position: relative;
width: 100%;
}
iframe {
height: 100%;
left: 0;
position: absolute;
top: 0;
width: 100%;
}
Float: CSS positiong property that changes page flow
#sidebar {
float: right;
}
Note Floats can be used for styling the whole page, but newer tools like Flexbox and Grid are better
Clear property allows element to resume normal document flow and “skip” the floated element.
Values:
#footer {
clear: both;
}
When all items in a parent elemnt are floated, it will “collapse”
May not be obvious if parent element has no background/border.
TO avoid issues, hould clear after elements but before container close.
Options:
<div style="clear: both;"></div>
.clearfix:after {
content: ".";
visibility: hidden;
display: block;
height: 0;
clear: both;
}
Issues w/ IE6 but IE going away so not important.