[CSS参考手册](http://css.doyoe.com/)»[问题和经验列表](#)»
相关内容:
[**其它问题和经验参考**选择其它项](#)
- [Bugs和解决方案](#)
- [技巧和经验](#)
- [其它技巧和经验](#)
# Bugs And Fixed
- Bugs和解决方案
### Bugs及解决方案列表(*以下实例默认运行环境都为Standard mode*):
1.
### 如何在IE6及更早浏览器中定义小高度的容器?
**方法:**
~~~
#test{overflow:hidden;height:1px;font-size:0;line-height:0;}
~~~
IE6及更早浏览器之所以无法直接定义较小高度的容器是因为默认会有行高
1.
### 如何解决IE6及更早浏览器浮动时产生双倍边距的BUG?
**方法:**
~~~
#test{display:inline;}
~~~
当在IE6及更早浏览器中出现浮动后margin值解析为双倍的情况,设置该元素的[display](#)属性为inline即可。
1.
### 如何在IE6及更早浏览器下模拟min-height效果?
**方法:**
~~~
#test{min-height:100px;_height:100px;}
~~~
注意此时#test不能再设置[overflow](#)的值为hidden,否则模拟[min-height](#)效果将失效
1.
### 如何解决按钮在IE7及更早浏览器下随着value增多两边留白也随着增加的问题?
**方法:**
~~~
input,button{overflow:visible;}
~~~
1.
### 如何解决IE7及更早浏览器下当li中出现2个或以上的浮动时,li之间产生的空白间隙的BUG?
**方法:**
~~~
li{vertical-align:top;}
~~~
除了top值,还可以设置为text-top | middle | bottom | text-bottom,甚至特定的[<length>](#)和[<percentage>](#)值都可以
1.
### 如何解决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为浮动
1.
### 如何解决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
1.
### 如何解决IE6使用滤镜PNG图片透明后,容器内链接失效的问题?
**方法:**
~~~
div{width:300px;height:100px;_filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='*.png');}
a{_position:relative;}
~~~
解决方法是为容器内的链接定义相对定位属性[position](#)的值为relative
1.
### 如何解决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-letter](#)和[E:first-line](#)选择符
1.
### 如何解决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规则。
1.
### 如何解决IE6会忽略同一条样式体内的!important规则的问题?
**BUG重现:**
~~~
div{color:#f00!important;color:#000;}
~~~
如上代码,IE6及以下浏览器div的文本颜色为#000,!important并没有覆盖后面的规则,也就是说!important被忽略了。解决方案是将该样式拆分为2条,细节参见[!important](#)规则
1.
### 如何解决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
1.
### 如何解决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
1.
### 如何解决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
1.
### 如何解决Chrome在应用transition时页面闪动的问题?
**方法:**
~~~
-webkit-transform-style:preserve-3d;或-webkit-backface-visibility:hidden;
~~~
在Chrome下,使用过渡效果transition时有时会出现页面闪动
待续及修订。。。
Copyright © 2006-2012 [Doyoe](http://www.doyoe.com/). All Rights Reserved
- 速查表 Quick Search
- CSS3列表 CSS3 List
- 简介 Introduction
- 关于本手册 About This Handbook
- 关于样式表 Introduction To CSS
- 关于作者 About The Author
- 阅读及使用指引 The Use Guides
- 鸣谢 Thank You
- 捐赠 Contribute
- 属性 Properties
- 定位(Positioning)
- position
- z-index
- top
- right
- bottom
- left
- 布局(Layout)
- display
- float
- clear
- visibility
- clip
- overflow
- overflow-x
- overflow-y
- 弹性盒模型(Flexible Box)
- box-orient
- box-pack
- box-align
- box-flex
- box-flex-group
- box-ordinal-group
- box-direction
- box-lines
- 尺寸(Dimension)
- width
- min-width
- max-width
- height
- min-height
- max-height
- 外补白(Margin)
- margin
- margin-top
- margin-right
- margin-bottom
- margin-left
- 内补白(Padding)
- padding
- padding-top
- padding-right
- padding-bottom
- padding-left
- 边框(Border)
- 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-color
- border-left
- border-left-width
- border-left-style
- border-left-color
- border-image
- border-radius
- border-top-left-radius
- border-top-right-radius
- border-bottom-right-radius
- border-bottom-left-radius
- box-shadow
- box-reflect
- 背景(Background)
- background
- background-color
- background-image
- background-repeat
- background-attachment
- background-position
- background-origin
- background-clip
- background-size
- Multiple background
- 颜色(Color)
- color
- opacity
- 字体(Font)
- font
- font-style
- font-variant
- font-weight
- font-size
- font-family
- font-stretch
- 文本(Text)
- text-indent
- text-overflow
- text-align
- text-transform
- text-decoration
- text-decoration-line
- text-decoration-color
- text-decoration-style
- text-shadow
- text-fill-color
- text-stroke
- text-stroke-width
- text-stroke-color
- letter-spacing
- word-spacing
- vertical-align
- word-wrap
- white-space
- direction
- unicode-bidi
- line-height
- tab-size
- 列表(List)
- list-style
- list-style-image
- list-style-position
- list-style-type
- 表格(Table)
- table-layout
- border-collapse
- border-spacing
- caption-side
- empty-cells
- 内容(Content)
- content
- counter-increment
- counter-reset
- quotes
- 用户界面(User Interface)
- 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
- 多栏(Multi-column)
- 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
- 2D变换(2D Transform)
- transform
- transform-origin
- 过渡(Transition)
- transition
- transition-property
- transition-duration
- transition-timing-function
- transition-delay
- 动画(Animation)
- animation
- animation-name
- animation-duration
- animation-timing-function
- animation-delay
- animation-iteration-count
- animation-direction
- animation-play-state
- animation-fill-mode
- 打印(Printing)
- page
- page-break-before
- page-break-after
- page-break-inside
- 媒体查询(Media Queries)
- 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-base-color
- scrollbar-track-color
- scrollbar-face-color
- filter
- behavior
- Only Firefox
- border-colors
- border-top-colors
- border-right-colors
- border-bottom-colors
- border-left-colors
- 选择符 Selectors
- 元素选择符
- 通配选择符(*)
- 类型选择符(E)
- ID选择符(E#myid)
- 类选择符(E.myclass)
- 关系选择符
- 包含选择符(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: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::selection
- 语法与规则 Rules
- !important
- comment
- @import
- @charset
- @media
- @font-face
- @page
- @keyframes
- 取值 Values
- 颜色(Color)
- Color Name
- HEX
- RGB
- RGBA
- HSL
- HSLA
- transparent
- 文本(Textual)
- <string>
- <url>
- <identifier>
- 函数(Functional)
- 图像(Image)
- 数字(Numeric)
- <number>
- <integer>
- 其它(Other)
- <length>
- <percentage>
- <angle>
- <time>
- <frequency>
- <fraction>
- <grid>
- 单位 Units
- 长度(Length)
- em
- ex
- ch
- rem
- vw
- vh
- vm
- cm
- mm
- in
- pt
- pc
- px
- 角度(Angle)
- deg
- grad
- rad
- turn
- 时间(Time)
- s
- ms
- 频率(Frequency)
- Hz
- kHz
- 布局(Layout-specific)
- fr
- gr
- 附录 Appendix
- 颜色关键字(Color Keywods)
- 媒体类型(Media Types)
- CSS Hack
- 条件Hack
- 属性级Hack
- 选择符级Hack
- 问题与经验 Experience
- Bugs和解决方案
- 技巧和经验
- 其它经验