最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
css margin叠加问题
时间:2022-07-02 12:17:24 编辑:袖梨 来源:一聚教程网
w3c认为margin叠加是合理的。不管是不是bug,但是这个问题真的存在。看下面这个例子:
- !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.*w**3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- html xmlns="http://www.**w*3.org/1999/xhtml">
- head>
- meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
- head>head>
- style type="text/">
- *{padding:0;margin:0;}
- .box{background:#ccc; }
- .content{background:#eee;margin: 20px auto;}
- .an-box{ margin:50px auto;background:#999999;}
- style>
- head>
- body>
- div class="box">
- div class="content">margin: 20px autodiv>
- div class="content">margin: 20px autodiv>
- div>
- div class="box">
- div class="content">margin: 20px autodiv>
- div>
- div class="box">
- div class="content">margin: 20px autodiv>
- div>
- div class="an-box">margin: 50px autodiv>
- body>
- html>
解决这个问题的方法有不少,先来看看这个,在外层的容器中加:overflow:hidden;zoom:1;
- !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.*w**3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- html xmlns="http://www.**w*3.org/1999/xhtml">
- head>
- meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
- head>head>
- style type="text/">
- *{padding:0;margin:0;}
- .box{background:#ccc; overflow:hidden;zoom:1 }
- .content{background:#eee;margin: 20px auto; }
- .an-box{ margin:50px auto;background:#999999;}
- style>
- head>
- body>
- div class="box">
- div class="content">这里两个还是存在叠加margin: 20px autodiv>
- div class="content">这里两个还是存在叠加margin: 20px autodiv>
- div>
- div class="box">
- div class="content">margin: 20px autodiv>
- div>
- div class="box">
- div class="content">margin: 20px autodiv>
- div>
- div class="an-box">margin: 50px autodiv>
- body>
- html>
还有外层的容器中加边框属性,在叠加元素加空块状元素等等。。还有就是用padding来取代margin
相关文章
- 荒原曙光奇物愈合珍珠怎么获得 奇物愈合珍珠获取攻略 10-15
- 荒原曙光黏土怎么获得 黏土获取攻略 10-15
- 荒原曙光奇物收容箱子怎么获得 奇物收容箱子获取攻略 10-15
- 荒原曙光雪莲怎么获得 雪莲获取攻略 10-15
- 荒原曙光怎么驯服动物 驯服动物方法 10-15
- 洛克王国世界火灵石怎么获得 火灵石获取攻略 10-15