Aims:
Assume nav
, then #main
, then aside
is the logical order
#wrapper { margin-left: auto; margin-right: auto; width: 76%; } nav { float: left; width: 20%; } #main { float: left; width: 55%; } aside { margin-left: 75%; } footer { clear: both; }
Class exercise: Suppose viewport is 1000px wide. How wide will #wrapper
, nav
, #main
and
aside
be?
#wrapper
#wrapper { margin-left: auto; margin-right: auto; width: 76%; min-width: 400px; max-width: 1000px; }The content will not exceed 1000px even if the viewport allows it. Equally, if the viewport is too small for 400px of content, a horizontal scrollbar will appear.
nav { float: left; width: 20%; min-width: 152px; }
@media screen and (max-width: 768px) { h1 { font-size: 1.5em; } h2 { font-size: 1.2em; } }The browser uses the enclosed CSS (e.g. scaling
h1
's to 1.5em instead of the more usual 2em)
only if the browser's viewport is no wider than 768px
width
refers to the viewport width (browser window): use it rather than device-width
(screen)
screen
, print
and 8 moremin-width
) and a value
(e.g. 768px
) in parentheses
min-width
rather than max-width
/* Styles that always apply, e.g.: */ body { font-family: Verdana, Arial, Helvetica, sans-serif; } #wrapper { margin: 0 10px 0 10px; background-color: #fff; } nav ul { list-style: none; } /* Styles that give a two-column layout when there is enough room, e.g.: */ @media screen and (min-width: 768px) { #wrapper { margin-left: auto; margin-right: auto; width: 76%; } nav { float: left; width: 20%; } #main { margin-left: 20%; } aside { margin-left: 20%; } footer { clear: both; } } /* Styles that give a three-column layout when there is even more room, e.g.: */ @media screen and (min-width: 1024px) { #main { float: left; width: 55%; margin-left: 0 } aside { margin-left: 75%; } }
320px | For small screen devices, like phones, held in portrait mode |
480px | For small screen devices, like phones, held in landscape mode |
600px | Smaller tables, like the Kindle (660×800) and Nook (600×1024), held in portrait mode |
768px | Ten-inch tablets like the iPad (768×1024) held in portrait mode |
1024px | Tablets like the iPad held in landscape mode, as well as some laptop, netbook and desktop displays |
1200px | For widescreen displays, primarily laptop and desktop browsers |
From Responsive Web Design, Ethan Marcotte
And see resizeMyBrowser
head
element to fix a problem with some mobile phone browsers:
<meta name="viewport" content="initial-scale=1.0, width=device-width" />