【发布时间】:2014-08-03 14:41:25
【问题描述】:
我有一个网页,其中包含三个单选按钮,其标签为 span 元素,样式为 display: inline-block,所有这些单选按钮都位于 div 中,样式为 float: right。这在除 IE8 之外的所有浏览器中都能正常呈现(当然)。
预期(铬版):
在 IE8 中的结果:
我能想出的最短重现代码如下:
<!DOCTYPE html>
<html>
<head>
<title>Home Page</title>
<style>
div {
//The issue remains whatever the value of float
//but disappears if I remove this line
float: right;
}
span {
//The issue disappears if I remove this line or use any other value
display: inline-block;
}
</style>
</head>
<body>
<div>
<span>Labello 1</span>
<span>Long Label 2</span>
<span>Labellebleue 3</span>
</div>
</body>
</html>
这无疑可以称为错误,但有什么“解释”吗?例如。听说过IE的“hasLayout”模型,但还没有完全掌握这个概念。
有没有实现相同效果的跨浏览器方式?我使用inline-block 的原因是在元素上使用边距和填充。不支持IE也没关系
在这个简单的示例中,如果我将span 元素替换为具有相同样式的div 元素,问题仍然存在,但如果我将div 元素与float: left 一起使用,问题就会消失。这是正确的解决方案吗?在将这个应用到我所有的真实(相当大的)页面之前,在应用这个解决方案之前我应该知道什么(基本上,左浮动divs 和内联块spans 之间的区别)?
【问题讨论】:
标签: html css internet-explorer-8 cross-browser