读书人

Firefox上margin-top有关问题

发布时间: 2012-11-08 08:48:11 作者: rapoo

Firefox下margin-top问题

(一)margin-top失效
?? 先看下面代码:

<div target="_blank" title="HTML/JavaScript教程">HTML</a> PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html <a href="http://www.blue1000.com/bkhtml/c21/" target="_blank" title="XML教程">XML</a>ns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Firefox下margin-top问题</title>
<style type="text/<a href="http://www.blue1000.com/bkhtml/c23/" target="_blank" title="CSS教程">CSS</a>">
<!--
* {
margin:0;
padding:0;
}
.box1{
float:left;
width:500px;
height:100px;
background:#999;
}
.box2{
margin-top:20px;
width:500px;
height:50px;
background:#000;
color:#fff;
clear:both;
}
-->
</style>
</head>
<body>
<div>
<div >float:left</div>
<div style="height:100px;background:red;">
??<div "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>Firefox下margin-top问题</title>
<style type="text/css">
<!--
* {
margin:0;
padding:0;
}
.box2{
margin-top:20px;
width:500px;
height:50px;
background:#000;
color:#fff;
}
-->
</style>
</head>
<body>
<div style="height:100px;background:red;">
<div class="box2">clear:both; margin-top:20px;height:50px;width:500px;background:#000;</div>
</div>
</body>
</html>

?

解决办法:

1.给父容器box加overflow:hidden;属性
2.父容器box加border除none以外的属性
3.用父容器box的padding-top代替margin-top

?

?

读书人网 >Web前端

热点推荐