隋唐演义前传:CSS常用技巧和兼容方案
来源:百度文库 编辑:九乡新闻网 时间:2024/10/06 01:18:24
基本上配合我以前所发的:Html+css小技巧收集,制作网页中经常 .. 和浏览器兼容性测试工具 可以做到所向无敌。
CSS HACK以下两种方法几乎能解决现今所有HACK.
1, !important
随着IE7对!important的支持, !important 方法现在只针对IE6的HACK.(注意写法.记得该声明位置需要提前.)
CSS代码
2, IE6/IE77对FireFox
*+html 与 *html 是IE特有的标签, firefox 暂不支持.而*+html 又为 IE7特有标签.
CSS代码
注意:
*+html 对IE7的HACK 必须保证HTML顶部有如下声明:
XML/HTML代码
万能 float 闭合(非常重要!)关于 clear float 的原理可参见 [How To Clear Floats Without Structural Markup]
将以下代码加入Global CSS 中,给需要闭合的div加上 class=”clearfix” 即可,屡试不爽.
CSS代码
三、其他兼容技巧(再次啰嗦)
1, FF下给 div 设置 padding 后会导致 width 和 height 增加, 但IE不会.(可用!important解决)
2, 居中问题.
1).垂直居中.将 line-height 设置为 当前 div 相同的高度, 再通过 vertical-align: middle.( 注意内容不要换行.)
2).水平居中. margin: 0 auto;(当然不是万能)
3, 若需给 a 标签内内容加上 样式, 需要设置 display: block;(常见于导航标签)
4, FF 和 IE 对 BOX 理解的差异导致相差 2px 的还有设为 float的div在ie下 margin加倍等问题.
5, ul 标签在 FF 下面默认有 list-style 和 padding . 最好事先声明, 以避免不必要的麻烦. (常见于导航标签和内容列表)
6, 作为外部 wrapper 的 div 不要定死高度, 最好还加上 overflow: hidden.以达到高度自适应.
7, 关于手形光标. cursor: pointer. 而hand 只适用于 IE.
PS:搞公司的站,IE6,IE7,FF下这些问题头大死了,后来经过这个文章的介绍终于解决了!
贴上代码:
CSS代码
css完美解决图片尺寸问题
经测试有效,设定图片最宽最高max-width,max-height在高版本的浏览器中都支持,但愚蒙的IE6不支持,这个css很好的解决了各个浏览器下图片尺寸比例的控制问题
定义css样式如下
png图片背景透明[修正全浏览器]
如果在网页中直接插入png图片想使其透明只需加入以下js代码,整个页面内的所有直接插入的png图片都可以实现透明:
--------------------------------------------------------------------
如果是想使用png做背景透明的话,需要用到css滤镜和hack:
============================================
IE6不支持PNG半透明图片的缺陷为web设计带来了极大的不便,之前曾经介绍过用滤镜+hack的方法实现显示PNG,不过实现起来相当繁琐。还有一种网上比较流行的方法,更加简便,下面详细介绍这种方法:
把以下代码保存为correctpng.js
使用的时候直接用img标签即可。注:使用此代码后,PNG透明的边会变成空,所以为了防止页面错乱,应设置好png的宽和高
CSS HACK以下两种方法几乎能解决现今所有HACK.
1, !important
随着IE7对!important的支持, !important 方法现在只针对IE6的HACK.(注意写法.记得该声明位置需要提前.)
CSS代码
引用
2, IE6/IE77对FireFox
*+html 与 *html 是IE特有的标签, firefox 暂不支持.而*+html 又为 IE7特有标签.
CSS代码
引用
注意:
*+html 对IE7的HACK 必须保证HTML顶部有如下声明:
XML/HTML代码
万能 float 闭合(非常重要!)关于 clear float 的原理可参见 [How To Clear Floats Without Structural Markup]
将以下代码加入Global CSS 中,给需要闭合的div加上 class=”clearfix” 即可,屡试不爽.
CSS代码
引用
三、其他兼容技巧(再次啰嗦)
1, FF下给 div 设置 padding 后会导致 width 和 height 增加, 但IE不会.(可用!important解决)
2, 居中问题.
1).垂直居中.将 line-height 设置为 当前 div 相同的高度, 再通过 vertical-align: middle.( 注意内容不要换行.)
2).水平居中. margin: 0 auto;(当然不是万能)
3, 若需给 a 标签内内容加上 样式, 需要设置 display: block;(常见于导航标签)
4, FF 和 IE 对 BOX 理解的差异导致相差 2px 的还有设为 float的div在ie下 margin加倍等问题.
5, ul 标签在 FF 下面默认有 list-style 和 padding . 最好事先声明, 以避免不必要的麻烦. (常见于导航标签和内容列表)
6, 作为外部 wrapper 的 div 不要定死高度, 最好还加上 overflow: hidden.以达到高度自适应.
7, 关于手形光标. cursor: pointer. 而hand 只适用于 IE.
PS:搞公司的站,IE6,IE7,FF下这些问题头大死了,后来经过这个文章的介绍终于解决了!
贴上代码:
CSS代码
引用 /* FF */
.submitbutton {
float:left;
width: 40px;
height: 57px;
margin-top: 24px;
margin-right: 12px;
}
/* IE6 */
*html .submitbutton {
margin-top: 21px;
}
/* IE7 */
*+html .submitbutton {
margin-top: 21px;
}
css完美解决图片尺寸问题
经测试有效,设定图片最宽最高max-width,max-height在高版本的浏览器中都支持,但愚蒙的IE6不支持,这个css很好的解决了各个浏览器下图片尺寸比例的控制问题
定义css样式如下
引用 img{vertical-align: middle;max-width: 630px; width: expression(this.width >630 && this.height < this.width ? 630: true); }
png图片背景透明[修正全浏览器]
如果在网页中直接插入png图片想使其透明只需加入以下js代码,整个页面内的所有直接插入的png图片都可以实现透明:
引用
--------------------------------------------------------------------
如果是想使用png做背景透明的话,需要用到css滤镜和hack:
引用 html>body .png { background:url(1.png); width:300px; height:100px; border:#000 solid 1px;}
/* ie6 */* html .png { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale, src='1.png');
background:none; width:300px; height:100px; border:#000 solid 1px;}
============================================
IE6不支持PNG半透明图片的缺陷为web设计带来了极大的不便,之前曾经介绍过用滤镜+hack的方法实现显示PNG,不过实现起来相当繁琐。还有一种网上比较流行的方法,更加简便,下面详细介绍这种方法:
把以下代码保存为correctpng.js
引用 function correctPNG()
{
for(var i=0; i{
var img = document.imagess
var imgName = img.src.toUpperCase()
if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
{
var imgID = (img.id) ? "id='" + img.id + "' " : ""
var imgClass = (img.className) ? "class='" + img.className + "' " : ""
var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
var imgStyle = "display:inline-block;" + img.style.cssText
if (img.align == "left") imgStyle = "float:left;" + imgStyle
if (img.align == "right") imgStyle = "float:right;" + imgStyle
if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
var strNewHTML = "+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
+ "(src=\'" + img.src + "\', sizingMethod='scale');\">"
img.outerHTML = strNewHTML
i = i-1
};
};
};
if(navigator.userAgent.indexOf("MSIE")>-1)
{
window.attachEvent("onload", correctPNG);
};
在网页的头部引用一下
使用的时候直接用img标签即可。注:使用此代码后,PNG透明的边会变成空,所以为了防止页面错乱,应设置好png的宽和高
CSS常用技巧和兼容方案
css兼容
说说CSS Hack和向后兼容 - 一起CSS
兼容IE6浏览器常用的十条CSS代码
常用CSS
DIV+CSS网页布局常用的方法与技巧
最常用的10种CSS BUG解决方法与技巧
常用css 样式
常用CSS特效文字
CSS常用文本属性
CSS浏览器兼容汇总 - 做最好的自己 - CSDN博客
IE6.0、IE7.0 与FireFox CSS兼容的解决方法
CSS:移动网站开发的前端技术和技巧
CSS兼容性(IE和Firefox)技巧大全
css滤镜失效问题解决方案
CSS兼容性技巧大全
CSS布局高级技巧
CSS新手整理的CSS技巧/
CSS元素命名常用关键字
CSS FireFox and IE 换行问题解决方案
CSS FireFox and IE 换行问题解决方案
最新区分兼容IE6/IE7/IE8/IE9/FF的CSS HACK写法
CSS文本溢出省略号:text-overflow:ellipsis及firefox兼容详解
极速模式和兼容模式