您的位置:首页 > Web前端 > CSS

html+css布局类型总结

2017-02-13 23:23 405 查看
思路:分析-设计-实现。

一般原则:从整体到局部,从上到下,从左到右。

通用的布局方式:

1.用HTML+CSS实现最简单的网页布局效果:一列布局

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>一列布局</title>
<style>
body{ margin:0; padding:0; font-size:30px; font-weight:bold}
div{ text-align:center; line-height:50px}
.head, .main, .footer{width:80%;margin:0 auto}
.head{ height:100px; background:#ccc}
.main{ height:300px; background:#FCC}
.footer{ height:50px; background:#9CF}
</style>
</head>

<body>
<div class="head">head</div>
<div class="main">main</div>
<div class="footer">footer</div>
</body>
</html>




2.自适应宽度及固定宽度的二列布局的实现。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>二列布局</title>
<style>
body{ margin:0; padding:0; font-size:30px; font-weight:bold}
div{ text-align:center; line-height:50px}
.main{ width:80%; height:600px; margin:0 auto}
.left{ width:20%; height:600px; background:#ccc; float:left}
.right{ width:80%; height:600px; background:#FCC; float:right}
</style>
</head>

<body>
<div class="main">
<div class="left">left</div>
<div class="right">right</div>
</div>
</body>
</html>




3. 用position定位方法实现自适应效果的三列布局。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>三列布局</title>
<style>
body{ margin:0; padding:0; font-size:30px; font-weight:bold}
div{ text-align:center; line-height:50px}
.left{ width:20%; height:600px; background:#ccc; position:absolute; left:0; top:0}
.main{ height:600px; margin:0 20%; background:#9CF}
.right{ height:600px; width:20%; position:absolute; top:0; right:0; background:#FCC;}
</style>
</head>

<body>

<div class="left">left</div>
<div class="main">main</div>
<div class="right">right</div>
</body>
</html>




4.用HTML+CSS实现复杂结构的混合布局。

核心代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>混合布局</title>
<style>
body{ margin:0; padding:0; font-size:30px; font-weight:bold}
div{ text-align:center; line-height:50px}
.head{ height:100px;background:#9CF}
.left{ width:20%; height:300px; background:#ccc; float:left}
.main{margin:0 20%;height:300px; background:#9CC }
.right{ width:20%; height:300px;background:#FCC; float:right}
.footer{ height:50px; background:#9F9; clear:both}
</style>
</head>

<body>
<div class="head">head</div>
<div class="left">left</div>
<div class="right">right</div>
<div class="main">main</div>
<div class="footer">footer</div>
</body>
</html>




 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html
xmlns="http://www.w3.org/1999/xhtml">
 <head>
 <meta
http-equiv="Content-Type"
content="text/html; charset=utf-8" />
 <title>三列布局</title>
 <style>
 body{ margin:0; padding:0; font-size:30px; font-weight:bold}
 div{ text-align:center; line-height:50px}
 .left{ width:20%; height:600px; background:#ccc; position:absolute; left:0; top:0}
 .main{ height:600px; margin:0 20%; background:#9CF}
 .right{ height:600px; width:20%; position:absolute; top:0; right:0; background:#FCC;}
 </style>
 </head>
  
 <body>
  
 <div
class="left">left</div>
 <div
class="main">main</div>
 <div
class="right">right</div>
 </body>
 </html>
 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: