五月 21, 2010
by 小寒
0 comments
请仔细观察下面的代码,在FF中是正常显示的,但在IE6中字体变成了红色。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>TEST</title>
<style type="text/css">
.span.text a {
color: red;
}
</style>
</head>
<body>
<span class="text"><a href="#">IE6下是红的</a></span>
</body>
</html>
象.a.b与.a.b.c这种写法,ie6只能识别最后一个选择器,也就是.b和.c。
CSS
五月 19, 2010
by 小寒
2 comments
在IE6下面,很多显示的BUG都可以用触发hasLayout的方式去解决。但有种情况正好相反,触发hasLayout之后会产生显示的BUG。请看下面的代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Demo</title>
<style type="text/css">
#div1 {
background: red;
margin: 10px;
padding: 10px;
}
#div2 {
background: gray;
margin: 30px;
padding: 10px;
}
</style>
</head>
<body>
<div id="div1">
<div id="div2">TEST</div>
<div>
</body>
</html>
上面的代码在所有浏览器里是正常显示的,包括IE6。但是给#div1设定宽度之后(触发hasLayout),经过大量测试,在IE6下#div1上面的padding会消失。有兴趣的同学可以看这篇文章:IE7-/Win: Margin collapsing and hasLayout
目前解决的办法就是去掉#div1的宽度,然后在#div1外面套一层div,在这个新div上设定宽度。解决问题的代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Demo</title>
<style type="text/css">
#con {
width: 400px;
}
#div1 {
background: red;
margin: 10px;
padding: 10px;
}
#div2 {
background: gray;
margin: 30px;
padding: 10px;
}
</style>
</head>
<body>
<div id="con">
<div id="div1">
<div id="div2">TEST</div>
<div>
</div>
</body>
</html>
CSS
四月 1, 2010
by 小寒
0 comments
IE6中设定了position: relative; float: left的容器下,如果存在着多个带有背景的列表,那么这些列表中有一部分会显示不正常,具体的表现为背景消失。例如下面的代码(请在IE6中查看):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>TEST</title>
</head>
<style type="text/css">
#container {
position: relative;
float: left;
}
#container li {
background: red;
}
</style>
<body>
<div id="container">
<ul>
<li>Hello Kitty</li>
<li>Hello Kitty</li>
<li>Hello Kitty</li>
<li>Hello Kitty</li>
<li>Hello Kitty</li>
</ul>
<ul>
<li>Hello Kitty</li>
<li>Hello Kitty</li>
<li>Hello Kitty</li>
<li>Hello Kitty</li>
<li>Hello Kitty</li>
</ul>
<ul>
<li>Hello Kitty</li>
<li>Hello Kitty</li>
<li>Hello Kitty</li>
<li>Hello Kitty</li>
<li>Hello Kitty</li>
</ul>
</div>
</body>
</html>
解决的方法是给li也加上position: relative。这个BUG的具体描述,请参考:http://www.positioniseverything.net/explorer/ie-listbug.html
CSS
三月 26, 2010
by 小寒
0 comments
在IE6,IE7下面给display: inline-block的元素设置text-indent: -9999px会把这个元素以及后面的元素拉走。请在IE6和IE7下,查看演示。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>TEST</title>
<style type="text/css">
.bar {
border: 1px solid;
display: inline-block;
height: 18px;
}
.bar .icon {
display: inline-block;
width: 16px;
height: 16px;
background: red;
text-indent: -9999px;
}
</style>
<!--[if lte IE 7]>
<style type="text/css">
.bar {
display: inline;
}
</style>
<![endif]-->
</head>
<body>
<input type="text" />
<div class="bar">
<span class="icon"></span>
<span>HELLO KITTY HELLO KITTY HELLO KITTY</span>
</div>
</body>
</html>
在IE6,IE7下可以看到.bar里面的内容都没有了。最开始的想法是让.icon浮动来解决这个问题,可是用css hack给.icon加上float: left居然不起作用,.icon后面的文字仍然被拉走。这时候只好在blueidea求助,结果那里的版主(yoom)想法和我的一样,让.icon浮动,但是他比我多加了个display: block,最终这个BUG被修正了。正常情况下,span元素加上float之后就已经是block级别了,但就是这个display: block起了决定性的作用,按yoom的话说,真是无心插柳啊。
最终的CSS HACK为:
<!--[if lte IE 7]>
<style type="text/css">
.bar {
display: inline;
}
.bar .icon {
display: block;
float: left;
}
</style>
<![endif]-->
CSS
三月 17, 2010
by 小寒
0 comments
Guillotine是一个在IE6下的BUG。表现的形式为:当鼠标放在一些链接上,浮动元素的下部会被裁剪掉。请用IE6查看演示
如何触发
如果让Guillotine“正常工作”,要满足下面几点:
- 有一个block级的包含元素(#container),不要触发layout。
- 在#container里有一个浮动的元素(#floated)。
- 在#float的后面有一些a标签,并且在a:hover里面要改变background。
其中第三点改变background很重要,经过测试如果不改变background,则在上面的条件下不会触发这个BUG。
如何修复
修复这个BUG有下面几个方法:
- 让#container触发layout。
- 在a:hover里面不要改变background。
- 在#container的后面添加一个清除浮动的元素。如:
<div id="container">
<div id="floated">
...
</div>
<a href="#">断头台</a><br />
...
</div>
<div style="clear: both"></div>
- 在#floated的后面加上清除浮动的元素。(不推荐,会带来新BUG。)
CSS