兼容性

IE6下子元素撑开父级宽度


在IE67下元素浮动,如果宽度需要内容撑开,就给里面的块元素都加浮动


在IE6,7下元素要通过浮动并在同一行,就给这行元素都加浮动


p中嵌套h,就会出现2个p标签


IE6下最小高度问题
在IE6下元素的高度小于19px的时候,会被当做19px来处理
解决办法:overflow:hidden;


1px dotted 在IE6下不支持
解决办法:切背景平铺,例如变成2px?


<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
<style>
body{margin:0;}
.box{background:blue;border:1px solid #000;zoom:1;}
.div{width:200px;height:200px;background:red;margin:100px;}
/*
	在IE6下解决margin传递要触发haslayout
	
	在IE6下父级有边框的时候,子元素的margin值消失
	
	解决办法:触发父级的haslayout:加zoom:1;

	或者给其一加上浮动
	或者overflow:hidden;zoom:1;
*/
</style>
</head>
<body>
<div class="box">
	<div class="div"></div>
</div>
</body>
</html>

IE6下双边距BUG
在IE6,块元素有浮动和和横向的margin值 ,横向的margin值会被放大成两倍
解决办法: display:inline;


<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
<style>
.box{ float:left;border:10px solid #000;}
.box div{width:100px;height:100px;background:Red;margin-right:20px;border:5px solid #ccc; float:left;}
/*
	margin-right 一行右侧第一个元素有双边距
	
	margin-left 一行左侧第一个元素有双边距
*/
</style>
</head>
<body>
<div class="box">
	<div>1</div>
    <div>2</div>
    <div>3</div>
    <div>4</div>
</div>
</body>
</html>

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
<style>
ul{margin:0;padding:0;width:302px;}
li{ list-style:none;height:30px;border:1px solid #000; vertical-align:top;}
a{width:100px;float:left;height:30px;background:Red;}
span{width:100px;float:right;height:30px;background:blue;}
/*
	在IE6,7下,li本身没浮动,但是li的内容有浮动,li下边就会产生一个间隙
	解决办法:
		1.给li加浮动
		2.给li加vertical-align
*/
</style>
</head>
<body>
<ul>
	<li>
    	<a href="#"></a>
        <span></span>
    </li>
    <li>
    	<a href="#"></a>
        <span></span>
    </li>
    <li>
    	<a href="#"></a>
        <span></span>
    </li>
</ul>
</body>
</html>

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
<style>
ul{margin:0;padding:0;width:302px;}
li{ list-style:none;height:12px;border:1px solid #000;overflow:hidden; float:left;width:300px;}
a{width:100px;float:left;height:12px;background:Red;}
span{width:100px;float:right;height:12px;background:blue;}
/*
	在IE6,7下,li本身没浮动,但是li的内容有浮动,li下边就会产生一个间隙
	解决办法:
		1.给li加浮动
		2.给li加vertical-align
		
		当IE6下最小高度问题,和 li的间隙问题共存的时候 给li加浮动 别忘记解决最小高度问题应加上overflow:hidden
*/
</style>
</head>
<body>
<ul>
	<li>
    	<a href="#"></a>
        <span></span>
    </li>
    <li>
    	<a href="#"></a>
        <span></span>
    </li>
    <li>
    	<a href="#"></a>
        <span></span>
    </li>
</ul>
</body>
</html>


当一行子元素占有的宽度之和和父级的宽度相差超过3px,或者有不满行状态的时候,最后一行子元素的下margin在IE6下就会失效


文字溢出bug

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
<style>
.box{ width:400px;}
.left{float:left;}
.right{width:400px;float:right;}
</style>
</head>
<body>
<div class="box">
	<div class="left"></div>
    <div><!-- IE6下的文字溢出BUG --><span></span></div>
    <div class="right">↓leo是个大胖子</div>
</div>
<!--
	在IE6下的文字溢出BUG
    
    子元素的宽度和父级的宽度相差小于3px的时候,两个浮动元素中间有注释或者内嵌元素
    
    解决办法:用div把注释或者内嵌元素用div包起来	
-->
</body>
</html>


<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
<style>
.box{ width:200px;height:200px;border:1px solid #000; position:relative;}
span{width:50px;height:50px;background:yellow; position:absolute;right:-20px;top:0;}
ul{width:150px;height:150px;background:Red;margin:0 0 0 50px;padding:0; float:left; display:inline;}/*IE6下双边距bug
在IE6下,块元素有浮动和横向的margin,横向的margin会被放大2倍
解决办法:display:inline*/
/*
	当浮动元素和绝对定位元素是并列关系的时候,在IE6下绝对定位元素会消失
	解决办法:
		给定位元素外面包个div
*/
</style>
</head>
<body>
<div class="box">
	<ul></ul>
    <div><span></span></div>
</div>
</body>
</html>

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
<style>
.box{ width:200px;height:200px;border:1px solid #000; overflow:auto; position:relative;}
.div{ width:150px;height:300px;background:yellow; position:relative;}
/*
	在IE6,7下,子元素有相对定位的话,父级的overflow包不住子元素
	
	解决办法: 给父级也加相对定位
*/
</style>
</head>
<body>
<div class="box">
	<div class="div"></div>
</div>
</body>
</html>


<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
<style>
.box{width:201px;height:201px;border:1px solid #000; position:relative;}
.box span{ width:20px;height:20px;background:yellow; position:absolute;right:-1px;bottom:-1px;}
/*
	在IE6下绝对定位元素的父级宽高是奇数的时候,元素的right值和bottom值会有1px的偏差 无法解决
*/
</style>
</head>
<body>
<div class="box">
	<span></span>
</div>
</body>
</html>

不要给tbody,tr,th同时加样式


<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
<style>
.box{ width:200px;height:32px;border:1px solid red;}
input{width:100px;height:30px;border:1px solid #000;margin:0;padding:0; float:left;}/*32+2?*/
/*
	在IE6,7下输入类型的表单控件上下各有1px的间隙
	
	解决办法:给input加浮动
*/
</style>
</head>
<body>
<div class="box">
	<input type="text" />
</div>
</body>
</html>


<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
<style>
.box{ width:200px;height:32px;border:1px solid red;background:yellow;}
input{width:100px;height:30px;border:none;margin:0;padding:0; float:left; background:#fff;}
/*
	在IE6,7下输入类型的表单控件上下各有1px的间隙
	
	解决办法:给input加浮动
	
	在IE6,7下输入类型的表单控件加border:none;
	
	解决办法: 重置input的背景
*/
</style>
</head>
<body>
<div class="box">
	<input type="text" />
</div>
</body>
</html>

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
<style>
.box{ width:100px;height:30px;border:1px solid red;background:yellow; background:url(ball.png) no-repeat;}
input{width:100px;height:30px;border:none;margin:0;padding:0; float:left; background:none;}
/*
	在IE6,7下输入类型的表单控件上下各有1px的间隙
	
	解决办法:给input加浮动
	
	在IE6,7下输入类型的表单控件加border:none;
	
	解决办法: 重置input的背景
	
	在IE6,7下输入类型的表单控件输入文字的时候,背景图片会跟着一块移动
	
	解决办法: 把背景加给父级
*/
</style>
</head>
<body>
<div class="box">
	<input type="text" />
</div>
</body>
</html>

IE6不支持png24图片。

JS插件(问题:不能处理body之上png24)

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
<style>
body{ background:#000;}
.box{width:400px;height:400px;background:url(img/png.png);}
</style>
<!--[if IE 6]>
<script src="DD_belatedPNG_0.0.8a.js"></script>
<script>
DD_belatedPNG.fix('.box');
</script>
<![endif]-->
</head>
<body>
<div class="box"></div>
</body>
</html>

原生滤镜
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
<style>
body{ background:#000;}
.box{width:400px;height:400px; background:url(img/png.png);_background:none;_filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src="img/png.png", sizingMethod="crop");
}
</style>
</head>
<body>
<div class="box"></div>
</body>
</html>

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
</head>
<body>
<!--[if IE]>
这是IE
<![endif]-->
<!--[if IE 9]>
9
<![endif]-->
<!--[if IE 8]>
8
<![endif]-->
<!--[if IE 7]>
7
<![endif]-->
<!--[if IE 6]>
6
<![endif]-->
</body>
</html>


<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
<style>
.box{ width:100px;height:100px;background:Red;background:blue\9; +background:yellow;_background:green;}
@media screen and (-webkit-min-device-pixel-ratio:0){.box{background:pink}}/* Webkit-Safari-Chrome */
/*
css hack:
	\9 IE10之前的IE浏览器解析
	+,* IE7包括IE7之前的IE浏览器解析
	_IE6包括IE6之前的IE浏览器	
*/
</style>
</head>
<body>
<div class="box"></div>
</body>
</html>

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
<style>
.box{width:100px;height:100px;background:red !important; background:pink;}
/*
	在IE6下 在important 后边在家一条同样的样式,会破坏掉important的作用,会按照默认的优先级顺序来走
	样式优先级:
	默认 < 类型 < class < id < style(行间) <important 

*/
</style>
</head>
<body>
<div class="box" style="background:#000;"></div>
</body>
</html>

圣杯布局(双飞翼布局)

左右宽度固定,中间宽度自适应伸缩;并且中间先加载

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
<style>
body{margin:0;}
.center{height:600px;background:#f60;margin:0 200px;}
.left{width:200px;background:#fc0;height:600px; position:absolute;left:0;top:0;}
.right{width:200px;background:#fcc;height:600px;position:absolute;right:0;top:0;}
</style>
</head>
<body>
<div class="center"></div>
<div class="left"></div>
<div class="right"></div>
</body>
</html>

等高布局

左右两列高度自适应扩展,并且相等;
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
<style>
body{margin:0;}
.wrap{ width:900px;margin:0 auto;overflow:hidden;}
.left{width:200px;background:Red;float:left;padding-bottom:10000px;margin-bottom:-10000px;}
.right{width:700px;background:blue;float:right;padding-bottom:10000px;margin-bottom:-10000px;}
</style>
</head>
<body>
<div class="wrap">
	<div class="left">
    	  页面内容<br/>
          页面内容<br/>
          页面内容<br/>
          页面内容<br/>
          页面内容<br/>
          页面内容<br/>
          页面内容<br/>
    </div>
    <div class="right">
    	  页面内容<br/>
          页面内容<br/>
          页面内容<br/>
          页面内容<br/>
          页面内容<br/>
          页面内容<br/>
          页面内容<br/>
          页面内容<br/>
          页面内容<br/>
          页面内容<br/>
          页面内容<br/>
          页面内容<br/>
          页面内容<br/>
          页面内容<br/>
    </div>
</div>
</body>
</html>

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
<style>
.box{float:left;border:10px solid #000;margin:20px; display:inline;}
.box div{width:100px;height:100px;background:red; position:relative;}/*relative使其正常超出范围*/
.div1{margin-top:-30px;}
.div2{margin-left:-30px;}
.div3{margin-bottom:-30px;}
.div4{margin-right:-30px;}
</style>
</head>
<body>
<div class="box">
	<div class="div1"></div>
</div>
<div class="box">
	<div class="div2"></div>
</div>
<div class="box">
	<div class="div3"></div>
</div>
<div class="box">
	<div class="div4"></div>
</div>
</body>
</html>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
<style>
body{margin:0;}
.wrap{ width:900px;margin:0 auto; border:10px solid #000; overflow:hidden;}/*overflow去掉黑框外多余的left和right*/
.wrap:after{content:"";display:block;clear:both;}
.left{width:200px;background:Red;float:left; padding-bottom:200px; margin-bottom:-200px;}/*最后2句撑开黑框*/
.right{width:200px;background:blue;float:right;padding-bottom:200px;margin-bottom:-200px;}
</style>
</head>
<body>
<div class="wrap">
	<div class="left">
    	 页面内容<br/>
         页面内容<br/>
         页面内容<br/>
         页面内容<br/>
         页面内容<br/>
    </div>
    <div class="right">
    </div>
</div>
</body>
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值