IE8下CSS写法的几点心得

html-css013

IE8下CSS写法的几点心得,第1张

width:192pxheight:55pxmargin-top:100pxbackground:url(images/anniu01.gif) no-repeat left bottom

要将上面的改成

width:192pxheight:155pxbackground:url(images/anniu01.gif) no-repeat left 50px

2.尽量用padding-top:,少用margin-top

今天总算升级到IE8了,感觉CSS的写法要想同时适应IE6、IE7、IE8、FireFox,有以下几个基本的窍门。

1、使用float后必须clear,否则IE8显示错误。

2、h1,h2,h3,ul,li,dl,dt,dd,p...最好定义margin:0和padding:0,否则各种浏览器显示有误差。

3、line-height值最好是偶数,奇数显示有误差。

4、input 的text和password两种形式在IE8不定义字体(宋体)下长度高度不一样,可将input定义为font-family:Arial。

5、如果想在标题前后加小图标,最好不要直接用img,用img的话IE6行间距会缩小,应该用<li>加背景的形式。

...今天暂时只发现这几点,更多的以后继续总结。

实在不行再用分开定义的办法:

div {

margin:0/* 给全部浏览器看 */

*margin:10px/* 给IE6、IE7看 */

_margin:20px/* 只给IE6看 */

}

附:基本CSS样式表

<style type="text/css">

body {

margin:0

font-size:9pt

line-height:18px

}

h1,h2,h3,ul,li,dl,dt,dd,p {

margin:0

padding:0

}

ul {

list-style:none

}

form {

margin:0

}

input,textarea,select {

font-family:Arial

font-size:9pt

}

.clear {

clear:both

}

</style>

要通过代码设置,C语言<!DOCTYPE HTML>

<html>

<head>

<meta charset="UTF-8">

<title>Demo</title> <style type="text/css">

#box { font-size: 4vw}</style></head><body> <div id="box">

我是靖鸣君 我是靖鸣君 我是靖鸣君</div></body></html>

但是该方案存在一个bug,上面的代码,当浏览器窗口变化的时候,box中的文字并没有按照应有的比例变化,但是css3标准中是这么说的:

When the height or width of the viewport is changed, they are scaled accordingly.

<!--[if IE 8]><link rel="stylesheet" type="text/css" href="特定的CSS文件URL" /><![endif]-->

以上CSS只有在IE8下才会加载,其他版本的浏览器浏览器不会加载

然后你就写你的特定css即可