最近在网上学习HTML,老师留了个画田字格的作业,恕我愚钝最终求助了百度经验,作者用了"clear:left"的方法来画,后来接着学发现只要用嵌套div的方法就可以画出来了,好开心,代码如下:
百度经验的代码:百度经验的链接配套详细说明字,很赞!
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>田字格布局</title>
<style>
#prat1{
width: 200px;
height: 200px;
background: blue;
float: left;
}
#prat2{
width: 200px;
height: 200px;
background: red;
float: left;
}
#prat3{
width: 200px;
height: 200px;
background: yellow;
float: left;
clear: left;
}
#prat4{
width: 200px;
height: 200px;
background: green;
float: left;
}
</style>
</head>
<body>
<div id="prat1">块1</div>
<div id="prat2">块2</div>
<div id="prat3">块3</div>
<div id="prat4">块4</div>
</body>
</html>
用嵌套的方法(我的第一段HTML代码,:-P)不需要用到“float:left”
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh-CN">
<head>
<style>
#top{
width:200px;
height:100px;
}
#bottom{
width:200px;
height:100px;
}
#top1{
width:100px;
height:100px;
float:left;
background:green;
}
#top2{
width:100px;
height:100px;
float:left;
background:red;
}
#btm1{
width:100px;
height:100px;
float:left;
background:orange;
}
#btm2{
width:100px;
height:100px;
float:left;
background:gray;
}
</style>
</head>
<body>
<div id="top">
<div id="top1">top1</div>
<div id="top2">top2</div>
</div>
<div id="bottom">
<div id="btm1">btm1</div>
<div id="btm2">btm2</div>
</div>
</body>
</html>
自己摸索程序确实有种莫名的快乐哟~~~