日期:2014-05-17  浏览次数:20617 次

CSS简单总结
  多篇文章的合并,向原作者致敬。

一、Hack



例如:style=”*width:10px!important; width:20px;”,其在 IE7下宽度为10px,在IE6下宽度是20px.

IE特有的html条件注释使用规则
1.仅IE可见的写法
<!--[if IE]>此处内容只有IE可见<![endif]–>
2.仅IE6可见的写法
<!-–[if IE 6]>此处内容只有IE6.0可见<![endif]–->
3.仅IE7可见的写法
<!–-[if IE 7]>此处内容只有IE7.0可见<![endif]–->
4.版本区间可显示写法
<!–[if lt IE 6]> IE6以及IE6以下版本可识别 <![endif]–>
<!–[if gte IE 6]> IE6以及IE6以上版本可识别 <![endif]–>
<!–[if lt IE 7]> IE7以及IE7以下版本可识别 <![endif]–>
<!–[if gte IE 7]> IE7以及IE7以上版本可识别 <![endif]–>
5.非IE可见的写法(注意:此条不符合WEB标准,但的确实用)
<!–[if !IE]>此处内容只非IE可见<![endif]–>

二、初始化
  由于各种浏览器对元素默认属性的定义不同,可能导致页面所有差异,于是,CSS Reset出现了。
  对各种元素的CSS属性进行重定义,达到各种浏览器无差异的效果。
1.
charset ”utf-8″;
html {background:url(/www/pic/head_back.gif) repeat-x top #FFF}
body {width:920px;font:12px Arial;margin:0 auto;padding:0;color:#000;}
a{color:#000; text-decoration:none}
a:hover {color:#f00; text-decoration:underline}
ul,ol,p,dl{margin:0;padding:0}
ul,ol,dl{height:100%;overflow:hidden}
li{list-style:none}
img {border:none}
h1,h2,h3,h4{font:12px Verdana;margin:0;padding:0}
input {font:12px Verdana}
2.

/*为背景定义了颜色*/
/*html {
color:#000;
background:#FFF;
}*/
body, div, dl, dt, dd, ul, ol, li, h1, h2, h3, h4, h5, h6, pre, code, form, fieldset, legend, input, textarea, p, blockquote, th, td {
margin:0;
padding:0;
}
/*合并边线,边线空间至零.*/
table {
border-collapse:collapse;
border-spacing:0;
}
/*清除边线*/
fieldset, img {
border:0;
}
address, caption, cite, code, dfn, em, strong, th, var {
font-style:normal;
font-weight:normal;
}
li {
list-style:none;
}
caption, th {
text-align:left;
}
h1, h2, h3, h4, h5, h6 {
font-size:100%;
font-weight:normal;
}
/*添加空字符清除融合*/
q:before, q:after {
content:”;
}
abbr, acronym {
border:0;
font-variant:normal;
}
/* to preserve line-height and selector appearance */
sup {
vertical-align:text-top;
}
sub {
vertical-align:text-bottom;
}
input, textarea, select {
font-family:inherit;
font-size:inherit;
font-weight:inherit;
}
/*to enable resizing for IE*/
/*在ie下重定义*/
input, textarea, select {
*font-size:100%;
}
/*because legend doesn’t inherit in IE */
/*IE下legend不继承 */
legend {
color:#000;
}

三、参数
ss和js带参数(形如.css?t=与.js?t=)

<script type="text/javascript" src="jb51.js?version=1.2.6"></script>
<link rel='stylesheet' href='base.css?version=2.3.3' type='text/css' />


使用参数有两种可能,

第一、脚本并不存在,而是服务端动态生成的,因此带了个版本号,以示区别。
      即上面代码对于文件来说 等价于

<script type="text/javascript" src="jb51.js"></script>
<link rel='stylesheet' href='base.css' type='text/css' />

但浏览器会认为他是 该文件的某个版本!
 
第二、客户端会缓存这些css或js文件,因此每次升级了js或css文件后,改变版本号,客户端浏览器就会重新下载新的js或css文件 ,刷性缓存的作用
第二种情况最多,也可能两种同时存在。

版本号,可以是一个随机数,也可以是一个递增的值,大版本小版本的方式,或者根据脚本的生成时间书写,比如 20080727182553 就是精确到了生成脚本的秒,而 2.3.3 就是大版本小版本的方式。

四、haslayout
引自:http://www.webjx.com/css/divcss-16025.html
要想更好的理解 css, 尤其是 IE 下对 css 的渲染,haslayout 是一个非常有必要彻底弄清除的概念。大多IE下的显示错误,就是源于 haslayout。

什么是 haslayout ?
haslayout 是Windows Internet Explorer渲染引擎的一个内部组成部分。在Internet Explorer中,一个元素要么自己对自身的内容进行计算大小和组织,要么依赖于父元素