ディレクトリ 検索
简介 更新历史 关于样式表 属性 定位 布局 position z-index top right bottom left clip display float clear visibility overflow overflow-x overflow-y 尺寸 width min-width max-width height min-height max-height 外补白 margin margin-top margin-right margin-bottom margin-left 内补白 padding padding-top padding-right padding-bottom padding-left 边框 border border-width border-style border-color border-top border-top-width border-top-style border-top-color border-right border-right-width border-right-style border-right-color border-bottom border-bottom-width border-bottom-style border-bottom-style border-bottom-color border-left border-left-width border-left-style border-left-color border-radius border-top-left-radius border-top-right-radius border-bottom-right-radius border-bottom-left-radius box-shadow border-image border-image-source border-image-slice border-image-width border-image-outset border-image-repeat 背景 background background-color background-image background-repeat background-attachment background-position background-origin background-clip background-size 颜色 color opacity 字体 font font-style font-variant font-weight font-size font-family font-stretch font-size-adjust 文本 text-transform white-space tab-size word-break word-wrap overflow-wrap text-align text-align-last text-justify word-spacing letter-spacing text-indent vertical-align line-height text-size-adjust 文本装饰 text-decoration text-decoration-line text-decoration-color text-decoration-style text-decoration-skip text-underline-position text-shadow 书写模式 direction unicode-bidi writing-mode 列表 list-style list-style-image list-style-position list-style-type 表格 table-layout border-collapse border-spacing caption-side empty-cells 内容 content counter-increment counter-reset quotes 用户界面 appearance text-overflow outline outline-width outline-color outline-style outline-offset nav-index nav-up nav-right nav-down nav-left cursor zoom box-sizing resize ime-mode user-select pointer-events 多列 columns column-width column-count column-gap column-rule column-rule-width column-rule-style column-rule-color column-span column-fill column-break-before column-break-after column-break-inside 伸缩盒(旧) box-orient box-pack box-align box-flex box-flex-group box-ordinal-group box-direction box-lines 伸缩盒(新) flex flex-grow flex-shrink flex-basis flex-flow flex-direction flex-wrap align-content align-items align-self justify-content order 变换 transform transform-origin transform-style perspective perspective-origin backface-visibility 过渡 transition transition-property transition-duration transition-timing-function transition-delay 动画 animation animation-name animation-duration animation-timing-function animation-delay animation-iteration-count animation-direction animation-play-state animation-fill-mode 打印 page page-break-before page-break-after page-break-inside 媒体查询 width height device-width device-height orientation aspect-ratio device-aspect-ratio color color-index monochrome resolution scan grid Only IE scrollbar-3dlight-color scrollbar-darkshadow-color scrollbar-highlight-color scrollbar-shadow-color scrollbar-arrow-color scrollbar-face-color scrollbar-track-color scrollbar-base-color filter behavior Only webkit -webkit-text-fill-color -webkit-text-stroke -webkit-text-stroke-width -webkit-text-stroke-color -webkit-box-reflect -webkit-tap-highlight-color -webkit-user-drag -webkit-overflow-scrolling 选择符 元素选择符 通配选择符(*) 类型选择符(E) ID选择符(E#id) 类选择符(E.class) 关系选择符 包含选择符(E F) 子选择符(E>F) 相邻选择符(E+F) 兄弟选择符(E~F) 属性选择符 E[att] E[att="val"] E[att~="val"] E[att^="val"] E[att$="val"] E[att*="val"] E[att|="val"] 伪类选择符 E:link E:visited E:hover E:active E:focus E:lang(fr) E:not(s) E:root E:first-child E:last-child E:only-child E:nth-child(n) E:nth-last-child(n) E:first-of-type E:last-of-type E:only-of-type E:nth-of-type(n) E:nth-last-of-type(n) E:empty E:checked E:enabled E:disabled E:target @page:first @page:left @page:right 伪对象选择符 E:first-letter/E::first-letter E:first-line/E::first-line E:before/E::before E:after/E::after E::placeholder E::selection 语法与规则 !important /*comment*/ @import @charset @media @font-face @page @keyframes @supports 取值与单位 长度 <length> em ex ch rem vw vh vmax vmin cm mm q in pt pc px 角度 <angle> deg grad rad turn 时间 <time> s ms 频率 <frequency> Hz kHz 布局 <fraction> <grid> fr gr 分辨率 <resolution> dpi dpcm dppx 颜色 <color> Color Name HEX RGB RGBA HSL HSLA transparent currentColor 文本 inherit initial unset <string> <url> <identifier> 函数 calc() toggle() 生成内容 counter() counters() attr() 图像 <image> image() image-set() <gradient> linear-gradient() radial-gradient() repeating-linear-gradient() repeating-radial-gradient() 数字 <number> <integer> <percentage> 附录 颜色关键字 媒体类型 CSS Hack 条件Hack 属性级Hack 选择符级Hack 问题和经验 Bugs和解决方案 技巧和经验 其它经验
テキスト

Bugs及解决方案列表(以下实例默认运行环境都为Standard mode):

  1. 如何在IE6及更早浏览器中定义小高度的容器?

    方法:

    #test{overflow:hidden;height:1px;font-size:0;line-height:0;}

    IE6及更早浏览器之所以无法直接定义较小高度的容器是因为默认会有行高

  2. 如何解决IE6及更早浏览器浮动时产生双倍边距的BUG?

    方法:

    #test{display:inline;}

    当在IE6及更早浏览器中出现浮动后margin值解析为双倍的情况,设置该元素的display属性为inline即可。

  3. 如何在IE6及更早浏览器下模拟min-height效果?

    方法:

    #test{min-height:100px;_height:100px;}

    注意此时#test不能再设置overflow的值为hidden,否则模拟min-height效果将失效

  4. 如何解决按钮在IE7及更早浏览器下随着value增多两边留白也随着增加的问题?

    方法:

    input,button{overflow:visible;}
  5. 如何解决IE7及更早浏览器下当li中出现2个或以上的浮动时,li之间产生的空白间隙的BUG?

    方法:

    li{vertical-align:top;}

    除了top值,还可以设置为text-top | middle | bottom | text-bottom,甚至特定的<length><percentage>值都可以

  6. 如何解决IE6及更早浏览器下的3像素BUG?

    方法:

    .a{color:#f00;}
    .main{width:950px;background:#eee;}
    .content{float:left;width:750px;height:100px;background:#ccc;_margin-right:-3px;}
    .aside{height:100px;background:#aaa;}
    
    <div class="main">
    	<div class="content">content</div>
    	<div class="aside">aside</div>
    </div>

    在IE6及更早浏览器下为.content设置margin-right:-3px;也可以设置.aside为浮动

  7. 如何解决IE6下的文本溢出BUG(江湖匪号:“谍影重重”或“一只猪的故事”)?

    BUG重现:

    .test{zoom:1;overflow:hidden;width:500px;}
    .box1{float:left;width:100px;}
    .box2{float:right;width:400px;}
    
    <div class="test">
    	<div class="box1"></div>
    	<!-- 注释 -->
    	<div class="box2">↓这就是多出来的那只猪</div>
    </div>

    运行如上代码,你会发现文字发生了溢出,在IE6下会多出一只“猪”。造成此BUG的原因可能是多重混合的,如浮动,注释,宽高定义等等。并且注释条数越多,溢出的文本也会随之增多。

    列举几个解决方法:
     删除box1和box2之间所有的注释;
     不设置浮动;
     调整box1或box2的宽度,比如将box的宽度调整为90px

  8. 如何解决IE6使用滤镜PNG图片透明后,容器内链接失效的问题?

    方法:

    div{width:300px;height:100px;_filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='*.png');}
    a{_position:relative;}

    解决方法是为容器内的链接定义相对定位属性position的值为relative

  9. 如何解决IE6无法识别伪对象:first-letter/:first-line的问题?

    方法1:

    p:first-letter {float:left;font-size:40px;font-weight:bold;}
    p:first-line {color:#090;}

    增加空格:在伪对象选择符:first-letter/:first-line与包含规则的花括号"{"间增加空格。

    方法2:

    p:first-letter
    {float:left;font-size:40px;font-weight:bold;}
    p:first-line
    {color:#090;}

    换行:将整个花括号"{"规则区域换行。细节参见E:first-letterE:first-line选择符

  10. 如何解决IE8会忽略伪对象:first-letter/:first-line里的!important规则的问题?

    BUG重现:

    p:first-letter {float:left;font-size:40px;font-weight:bold;color:#f00!important;color:#090;}

    如上代码,在IE8下color定义都会失效,原因就是因为有color使用了!important规则。鉴于此,请尽量不要在:first-letter/:first-line里使用!important规则。

  11. 如何解决IE6会忽略同一条样式体内的!important规则的问题?

    BUG重现:

    div{color:#f00!important;color:#000;}

    如上代码,IE6及以下浏览器div的文本颜色为#000,!important并没有覆盖后面的规则,也就是说!important被忽略了。解决方案是将该样式拆分为2条,细节参见!important规则

  12. 如何解决IE6及更早浏览器下当li内部元素是定义了display:block的内联元素时底部产生空白的问题?

    BUG重现:

    a,span{display:block;background:#ddd;}
    
    <ul>
    	<li><a href="http://css.doyoe.com/">CSS参考手册</a></li>
    	<li><a href="http://blog.doyoe.com/">CSS探索之旅</a></li>
    	<li><a href="http://demo.doyoe.com/">web前端实验室</a></li>
    	<li><span>测试li内部元素为设置了display:block的内联元素时底部产生空白</span></li>
    </ul>

    如上代码,IE6及更早浏览器每个li内部的内联元素底部都会产生空白。解决方案是给li内部的内联元素再加上zoom:1

  13. 如何解决IE6及更早浏览器下未定义宽度的浮动或绝对定位元素会被内部设置了zoom:1的块元素撑开的问题?

    BUG重现:

    #test{zoom:1;overflow:hidden;border:1px solid #ddd;background:#eee;}
    #test h1{float:left;}
    #test .nav{float:right;background:#aaa;}
    #test .nav ul{zoom:1;overflow:hidden;margin:0;padding:0;list-style:none;}
    #test .nav li{float:left;margin:0 5px;}
    
    <div id="test">
    	<h1>Doyoe</h1>
    	<div class="nav">
    		<ul>
    			<li><a href="http://css.doyoe.com/">CSS参考手册</a></li>
    			<li><a href="http://blog.doyoe.com/">CSS探索之旅</a></li>
    			<li><a href="http://demo.doyoe.com/">web前端实验室</a></li>
    		</ul>
    	</div>
    </div>

    如上代码,IE6及更早浏览器div.nav会被设置了zoom:1的ul给撑开。

    列举几个解决方法:
     设置ul为浮动元素;
     设置ul为inline元素;
     设置ul的width

  14. 如何解决IE7及更早浏览器下子元素相对定位时父元素overflow属性的auto|hidden失效的问题?

    BUG重现:

    div{overflow:auto;width:260px;height:80px;border:1px solid #ddd;}
    p{position:relative;margin:0;}
    
    <div>
    	<p>如果我是相对定位,我的父元素overflow属性设置为auto|hidden将失效。如果你使用的是IE及更早浏览器,你将可以看到这个BUG</p>
    	<p>如果我是相对定位,我的父元素overflow属性设置为auto|hidden将失效。如果你使用的是IE及更早浏览器,你将可以看到这个BUG</p>
    </div>

    如上代码,在IE7及更早浏览器下你会看到div的滚动条将无法工作。解决方案是给div也设置相对定位position:relative

  15. 如何解决Chrome在应用transition时页面闪动的问题?

    方法:

    -webkit-transform-style:preserve-3d;或-webkit-backface-visibility:hidden;

    在Chrome下,使用过渡效果transition时有时会出现页面闪动


前の記事: 次の記事: