指导一个简单的css+div代码
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/...
<!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=gb2312" />
<title>无标题文档</title>
<link type="text/css" href="index1.css" rel="stylesheet"/>
</head>
<body>
<div class="blue">
<div class="white1">头部</div>
<div class="white">内容部分</div>
<div class="white2">尾部</div>
</div>
</body>
</html>
css代码
body{ text-align:center;margin:0; padding:0;}
div{ margin:0 auto;}
.blue{ background:#34d5f2; width:500px; height:500px; margin-top:100px;}
.white{ background:white; width:400px; height:250px; margin-bottom:50px;}
.white1{ background:white; width:400px; height:50px; margin-bottom:50px; margin-top:150px;}
.white2{ background:white; width:400px; height:50px; margin-bottom:150px;} 展开
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<link type="text/css" href="index1.css" rel="stylesheet"/>
</head>
<body>
<div class="blue">
<div class="white1">头部</div>
<div class="white">内容部分</div>
<div class="white2">尾部</div>
</div>
</body>
</html>
css代码
body{ text-align:center;margin:0; padding:0;}
div{ margin:0 auto;}
.blue{ background:#34d5f2; width:500px; height:500px; margin-top:100px;}
.white{ background:white; width:400px; height:250px; margin-bottom:50px;}
.white1{ background:white; width:400px; height:50px; margin-bottom:50px; margin-top:150px;}
.white2{ background:white; width:400px; height:50px; margin-bottom:150px;} 展开
3个回答
展开全部
首先,建议你一点,与其在上一个div里面用margin-bottom不如在下一个div里面用margin-top,因为margin-bottom经常会失效,
而你这样的布局可以这样写
<style>
*{margin:0px;padding:0px;}
body{margin:0px auto;}
.blue{margin:0px auto;background:#34d5f2;padding:150px 50px;margin-top:100px;width:500px;overflow:hidden;}
.white{margin-top:50px;background:#fff;}
.white1{width:400px;height:250px;}
.white{width:400px;height:500px;margin-top:50px;}
.white2{width:400px;height:50px;margin-top:50px;}
.white,.white1,.white2{background:#fff;}
</style>
<body>
<div class="blue">
<div class="white1">头部</div>
<div class="white">内容部分</div>
<div class="white2">尾部</div>
</div>
</body>
</html>
这样就是你要的效果了
而你这样的布局可以这样写
<style>
*{margin:0px;padding:0px;}
body{margin:0px auto;}
.blue{margin:0px auto;background:#34d5f2;padding:150px 50px;margin-top:100px;width:500px;overflow:hidden;}
.white{margin-top:50px;background:#fff;}
.white1{width:400px;height:250px;}
.white{width:400px;height:500px;margin-top:50px;}
.white2{width:400px;height:50px;margin-top:50px;}
.white,.white1,.white2{background:#fff;}
</style>
<body>
<div class="blue">
<div class="white1">头部</div>
<div class="white">内容部分</div>
<div class="white2">尾部</div>
</div>
</body>
</html>
这样就是你要的效果了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询