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>
![](https://img-blog.csdn.net/20170213232427828?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdzExODY3NTEzMDU=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
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>
![](https://img-blog.csdn.net/20170213232436440?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdzExODY3NTEzMDU=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
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>
![](https://img-blog.csdn.net/20170213232436440?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdzExODY3NTEzMDU=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
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>
![](https://img-blog.csdn.net/20170213232453782?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdzExODY3NTEzMDU=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
一般原则:从整体到局部,从上到下,从左到右。
通用的布局方式:
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> | |
相关文章推荐
- 7-HTML+CSS页面布局重点总结
- Head first HTML and CSS 总结- 12.布局和排版
- HTML与CSS布局技巧总结
- html+css常见布局类型
- HTML与CSS布局技巧总结
- HTML+CSS总结(2)选择器的类型
- HTML与CSS布局技巧总结
- HTML与CSS布局技巧总结
- Html+CSS_居中布局的总结
- css+div布局总结--新手入门
- DIV+CSS布局基础:HTML标记(二)
- 用CSS防止HTML页面输入字符过多撑大布局
- HTML结构化:CSS布局入门指南
- DIV+CSS布局基础:HTML标记(三)
- XHTML教程 CSS网页布局中HTML标签的语义(一)
- 样式 css HTML 常用总结
- 布局用CSS+DIV的优点总结
- HTML结构化:实践DIV+CSS网页布局入门指南
- HTML结构化CSS网页布局入门指南
- XHTML下css+div布局总结 超强推荐