css中一些兼容性问题和技巧

时间:2026-04-29

本文概括总结了一些web制作中css在各浏览器中不兼容的小问题。包括:一、设置float:left时父元素height不能自适应的兼容问题。二、当同时设置float:left和margin时IE6会产生双倍margin值。三、margin不能撑开height。四、margin-top失效。五、子元素设置margin-top作用于父元素。六、图片产生间距的问题。七、IE6不支持 min-height。八、透明度的问题。

一、设置float:left时父元素height不能自适应的兼容问题 代码:

<style type="text/css">

#box{ width:800px; border:5px #333333 solid;}

#left{ width:360px; background:#FF0000;height:250px; float:left;} #right{float:left; width:360px; background:#0000FF;height:250px;} </style> <body>

<div id="box"> <div id="left"></div> <div id="right"></div> </div> </body>

(1)在IE6和IE7中显示如下:

(2)在IE8和IE9 中显示如下:

(3)在firefox和opera中显示如下:

解决办法:在父元素中添加 overflow:hidden 代码如下:

<style type="text/css">

#box{ width:800px; border:5px #333333 solid;overflow;hidden} #left{ width:360px; background:#FF0000;height:250px; float:left;}

本文概括总结了一些web制作中css在各浏览器中不兼容的小问题。包括:一、设置float:left时父元素height不能自适应的兼容问题。二、当同时设置float:left和margin时IE6会产生双倍margin值。三、margin不能撑开height。四、margin-top失效。五、子元素设置margin-top作用于父元素。六、图片产生间距的问题。七、IE6不支持 min-height。八、透明度的问题。

#right{float:left; width:360px; background:#0000FF;height:250px;} </style>

修改后:IE、firefox、opera 中显示如下:

二、当同时设置float:left和margin时IE6会产生双倍margin值 代码如下:

<style type="text/css">

#box{ width:800px; border:5px #333333 solid; overflow:hidden}

#left{ width:360px; background:#FF0000;height:250px; float:left; margin:0px 20px;} #right{float:left; width:360px; background:#0000FF;height:250px; margin:0px 20px;} </style> </head> <body>

<div id="box"> <div id="left"></div> <div id="right"></div> </div> </body>

在IE6中显示如下:

在IE7、IE8、IE9、firefox、opera中显示如图:

解决方法:添加display:inline

修改后:IE、firefox、opera 中显示如下:

本文概括总结了一些web制作中css在各浏览器中不兼容的小问题。包括:一、设置float:left时父元素height不能自适应的兼容问题。二、当同时设置float:left和margin时IE6会产生双倍margin值。三、margin不能撑开height。四、margin-top失效。五、子元素设置margin-top作用于父元素。六、图片产生间距的问题。七、IE6不支持 min-height。八、透明度的问题。

三、margin不能撑开height 代码如下:

<style type="text/css">

#box {background-color:#eee; width:300px; }

#inbox{margin-top: 20px;margin-bottom: 20px; text-align:center } </style> <body>

<div id="box">

<div id="inbox">对象中的内容</div> </div> </body>

(1) IE6和IE7能够撑开,如图:

(2) IE8 、IE9、firefox、和opera不能撑开。如图:

解决办法一:在#inbox对象上下各加2个空的div对象CSS代码:.1{height:0px;overflow:hidden;} 代码如下:

<style type="text/css">

#box {background-color:#eee; width:300px; }

#inbox{margin-top: 20px;margin-bottom: 20px; text-align:center;} .hidden{height:0px;overflow:hidden} </style> <body>

<div id="box">

<div class="hidden"></div>

<div id="inbox">p对象中的内容</div> <div class="hidden"></div> </div> </body>

修改后: IE、firefox、opera 显示如图:

本文概括总结了一些web制作中css在各浏览器中不兼容的小问题。包括:一、设置float:left时父元素height不能自适应的兼容问题。二、当同时设置float:left和margin时IE6会产生双倍margin值。三、margin不能撑开height。四、margin-top失效。五、子元素设置margin-top作用于父元素。六、图片产生间距的问题。七、IE6不支持 min-height。八、透明度的问题。

解决方法二:为#box加上border属性 代码如下:

<style type="text/css">

#box {background-color:#eee; width:300px; border:1px #666666 solid } #inbox{margin-top: 20px;margin-bottom: 20px; text-align:center;} </style> <body>

<div id="box">

<div id="inbox">p对象中的内容</div> </div> </body>

修改后: IE、firefox、opera 显示如图:

四、margin-top失效 代码如下:

<style type="text/css"> <!-- * { 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> <body> <div>

<div class="box1" >float:left</div>

<div class="box2">clear:both; margin-top:20px;</div>

本文概括总结了一些web制作中css在各浏览器中不 …… 此处隐藏:3095字,全部文档内容请下载后查看。喜欢就下载吧 ……

css中一些兼容性问题和技巧.doc 将本文的Word文档下载到电脑

    精彩图片

    热门精选

    大家正在看

    Copyright © 2023-2025 学科文库 版权所有
    本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
    客服QQ:370150219 邮箱:370150219@qq.com
    苏ICP备16052595号-5

    × 游客快捷下载通道(下载后可以自由复制和排版)

    限时特价:4.9 元/份 原价:20元

    支付方式:

    开通VIP包月会员 特价:19元/月

    注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
    微信:fanwen365 QQ:370150219