狂四郎
2017-01-04 13:58
<!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>
*{margin:0;padding:0}
#box1{width:200px;height:200px;background:red;}
#box2{width:100px;height:100px;background:yellow;margin-top:50px}
</style>
</head>
<body>
<div id="box1">
<div id="box2">fsbhsrndtyjntm
</div>
</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>
*{margin:0;padding:0}
#box1{width:200px;height:200px;background:red;position:relative;}
#box2{width:100px;height:100px;background:yellow;margin-top:50px;position:absolute;}
/*你是要这种效果吗?*/
</style>
</head>
<body>
<div id="box1">
<div id="box2">fsbhsrndtyjntm
</div>
</div>
</body>
</html>
这段代码你测试一下,就是你说的那种效果啊,box2现在距离box1顶部50px,你看下吧
应该加一个position:absolute 在box2的格式中
初识HTML(5)+CSS(3)-升级版
1225812 学习 · 18234 问题
相似问题