css兼容问题
1.最主要也是最常见的,就是浏览器对标签的默认支持不同,所以我们要统一,就要进行CSS reset . 最简单的初始化方法是 *{margin:0; padding:0;} 但不推荐,而且它也并不完善。
最好是有一个reset.css的初始化样式,这样的话,更具体;
淘宝的样式初始化
body, h1, h2, h3, h4, h5, h6, hr, p, blockquote, dl, dt, dd, ul, ol, li, pre, form, fieldset, legend, button, input, textarea, th, td { margin:0; padding:0; } body, button, input, select, textarea { font:12px/1.5tahoma, arial, \5b8b\4f53; } h1, h2, h3, h4, h5, h6{ font-size:100%; } address, cite, dfn, em, var { font-style:normal; } code, kbd, pre, samp { font-family:couriernew, courier, monospace; } small{ font-size:12px; } ul, ol { list-style:none; } a { text-decoration:none; } a:hover { text-decoration:underline; } sup { vertical-align:text-top; } sub{ vertical-align:text-bottom; } legend { color:#000; } fieldset, img { border:0; } button, input, select, textarea { font-size:100%; } table { border-collapse:collapse; border-spacing:0; }
2.IE6双边距bug: 块属性标签添加了浮动float之后,若在浮动方向上也有margin值,则margin值会加倍。其实这种问题主要就是会把某些元素挤到了第二行
解决的方式有两个:
1.给float元素添加display:inline 即可正常显示
2.就是hack处理了,对IE6进行 _margin-left:5px;
3.chrome下默认会将小于12px的文本强制按照12px来解析。解决办法是给其添加属性:
html{ -webkit-text-size-adjust: none; }
4.因为存在两种盒子模式:IE盒子模式(怪异盒)和W3C标准模式(标准盒),所以对象的实际宽度也要注意。
可以在css对一个元素进行两种模式的转变(非IE):设置 box-sizing: border-box;(变异盒)或者 bix-sizing: content-box(标准盒)
两种盒子的区别就是(针对width来说):变异盒:你所设定的width就是 标准盒的width+padding+border,即如果你想知道内容的高度的话,还要用你设定的width-padding-border才能得知;
标准盒:你所设定的width就是内容的高度,你想知道盒子的高度的话,需要用你设定的width+padding+border才能得知