Problem
Figure 7-3. One-column page reinforced by increased margin
Solution
body {
margin-left:15%;
margin-right: 15%;
}
Discussion
When you apply a percentage value to the left and right margins
of the body, the column width becomes flexible. This allows the content to
stretch to the width of the user's browser.
body {
width: 600px;
}
This technique aligns the column to the left side of the user's
browser. If you want to center a column with a fixed width, wrap a div
element around the entire contents of the web document with a specific, unique
id attribute such as a frame:
<div id="frame"> [...] </div>
body {
width: 600px;
padding-left: 50%;
}
Through an id selector, set the width of the column,
then set a negative left margin equal to half the column width:
#frame {
/* set the width of the column */
width: 600px;
margin-left: -300px;
}
You might think to just set the left and right margins to
auto:
#frame {
width: 600px;
margin-left: auto;
margin-right: auto;
}
This straightforward approach doesn't work in Internet Explorer
for Windows, however. The Solution uses a workaround that works on all major
browsers.
