精通css:高级Web标准解决方案之两列布局
1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2<html xmlns="http://www.w3.org/1999/xhtml">
3<head>
4<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5<title>Floated Two Col Layout</title>
6<style type="text/css">
7<!--
8
9/* Pretty Stuff
10================================== */
11
12/* Zero down margin and paddin on all elements */
13* {
14 margin: 0;
15 padding: 0;
16}
17
18body {
19 font: 62.5%/1.6 "Lucida Grande", "Lucida Sans", "Lucida Sans Unicode", Verdana, sans-serif;
20 background-color:#D4D4D4;
21}
22
23h1 {
24 font-size: 2.4em;
25 font-weight: normal;
26}
27
28h2 {
29 font-size: 2.0em;
30 font-weight: normal;
31}
32
33p, li {
34 font-size: 1.4em;
35}
36
37h1, h2, p {
38 margin: 1em 0;
39}
40
41#branding h1 {
42 margin: 0;
43}
44
45#branding {
46 height: 50px;
47 background-color:#b0b0b0;
48 padding: 20px;
49}
50
51#mainNav {
52 list-style: none;
53}
54
55#footer {
56 background-color:#b0b0b0;
57 padding: 1px 20px;
58}
59
60/* The Core Technique
61================================= */
62
63body {
64 text-align: center;
65 min-width: 760px;
66}
67
68#wrapper {
69 width: 720px;
70 margin: 0 auto;
71 text-align: left;
72 background: #fff url(images/nav-bg-fixed.gif) repeat-y left top;
73}
74
75
76#content {
77 width: 520px;
78 float: right;
79}
80
81#mainNav {
82 width: 180px;
83 float: left;
84}
85
86#footer {
87 clear: both;
88}
89
90/* Add some padding
91================================== */
92
93#mainNav {
94 padding-top: 20px;
95 padding-bottom: 20px;
96}
97
98#mainNav * {
99 padding-left: 20px;
100 padding-right: 20px;
101}
102
103#mainNav * * {
104 padding-left: 0;
105 padding-right: 0;
106}
107
108#content * {
109 padding-right: 20px;
110}
111
112#content * * {
113 padding-right: 0;
114}
115
116-->
117</style>
118</head>
119
120<body>
121
122<div id="wrapper">
123<div id="branding">
124<h1>Branding</h1>
125</div>
126
127<div id="content">
128<h1>Lorem ipsum dolor</h1>
129<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla.</p>
130<h2>Ea commodo consequat</h2>
131<p>Ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper.</p>
132<p>Ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh.</p>
133<h2>Magna aliquam erat volutpat</h2>
134<p>Magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</p>
135<p>Aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</p>
136</div>
137
138<ul id="mainNav">
139<li class="first"><a href="#">Home</a></li>
140<li><a href="#">About</a></li>
141<li><a href="#">News</a></li>
142<li><a href="#">Products</a></li>
143<li><a href="#">Services</a></li>
144<li><a href="#">Clients</a></li>
145<li><a href="#">Case Studies</a></li>
146</ul>
147
148<div id="footer">
149<p>Footer</p>
150</div>
151
152
153</div>
154
155</body>
156</html>
157
2<html xmlns="http://www.w3.org/1999/xhtml">
3<head>
4<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5<title>Floated Two Col Layout</title>
6<style type="text/css">
7<!--
8
9/* Pretty Stuff
10================================== */
11
12/* Zero down margin and paddin on all elements */
13* {
14 margin: 0;
15 padding: 0;
16}
17
18body {
19 font: 62.5%/1.6 "Lucida Grande", "Lucida Sans", "Lucida Sans Unicode", Verdana, sans-serif;
20 background-color:#D4D4D4;
21}
22
23h1 {
24 font-size: 2.4em;
25 font-weight: normal;
26}
27
28h2 {
29 font-size: 2.0em;
30 font-weight: normal;
31}
32
33p, li {
34 font-size: 1.4em;
35}
36
37h1, h2, p {
38 margin: 1em 0;
39}
40
41#branding h1 {
42 margin: 0;
43}
44
45#branding {
46 height: 50px;
47 background-color:#b0b0b0;
48 padding: 20px;
49}
50
51#mainNav {
52 list-style: none;
53}
54
55#footer {
56 background-color:#b0b0b0;
57 padding: 1px 20px;
58}
59
60/* The Core Technique
61================================= */
62
63body {
64 text-align: center;
65 min-width: 760px;
66}
67
68#wrapper {
69 width: 720px;
70 margin: 0 auto;
71 text-align: left;
72 background: #fff url(images/nav-bg-fixed.gif) repeat-y left top;
73}
74
75
76#content {
77 width: 520px;
78 float: right;
79}
80
81#mainNav {
82 width: 180px;
83 float: left;
84}
85
86#footer {
87 clear: both;
88}
89
90/* Add some padding
91================================== */
92
93#mainNav {
94 padding-top: 20px;
95 padding-bottom: 20px;
96}
97
98#mainNav * {
99 padding-left: 20px;
100 padding-right: 20px;
101}
102
103#mainNav * * {
104 padding-left: 0;
105 padding-right: 0;
106}
107
108#content * {
109 padding-right: 20px;
110}
111
112#content * * {
113 padding-right: 0;
114}
115
116-->
117</style>
118</head>
119
120<body>
121
122<div id="wrapper">
123<div id="branding">
124<h1>Branding</h1>
125</div>
126
127<div id="content">
128<h1>Lorem ipsum dolor</h1>
129<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla.</p>
130<h2>Ea commodo consequat</h2>
131<p>Ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper.</p>
132<p>Ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh.</p>
133<h2>Magna aliquam erat volutpat</h2>
134<p>Magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</p>
135<p>Aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</p>
136</div>
137
138<ul id="mainNav">
139<li class="first"><a href="#">Home</a></li>
140<li><a href="#">About</a></li>
141<li><a href="#">News</a></li>
142<li><a href="#">Products</a></li>
143<li><a href="#">Services</a></li>
144<li><a href="#">Clients</a></li>
145<li><a href="#">Case Studies</a></li>
146</ul>
147
148<div id="footer">
149<p>Footer</p>
150</div>
151
152
153</div>
154
155</body>
156</html>
157
可以将填充从内容元素上去掉,并且将它应用于次要内容的内容上,从而让布局显得更有条理