button - IE8 按钮元素内的绝对定位元素错误

标签 button internet-explorer-8 css-position

标题说明了一切:按钮元素的绝对定位子元素在 IE8 中是错误的
这是一个 fiddle
这是强制性的代码:

<button><div></div></button>
<style>
button{
    position: relative;
    width: 200px;
    height: 200px;
    border: 0;
    background: gray;
}
button div{
    position: absolute;
    top: 5px;
    left: 0px;
    width: 100px;
    height: 100px;
    background: red;
}​
</style>

我搜索并尝试了所有我能想到的方法。也许我应该放弃使用按钮元素 :-/

这是怎么回事?

最佳答案

您需要添加一个 overflow:visible 到按钮 css。

这是一个 fiddle https://jsfiddle.net/innerurge1/os2e9c2j/7/ .此外,您应该用 span 换掉 div,因为这更符合语义。 Div 在按钮中是“不允许的”,因为它们是 block 元素并且按钮是内联的。

.parent{
    position: relative;
    width: 200px;
    height: 200px;
    border: 0;
    background: gray;
    text-align : left;
    overflow:visible;
}

关于button - IE8 按钮元素内的绝对定位元素错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14129550/

相关文章:

javascript - X 上的 Dojo 对话关闭事件(右上)

javascript - 具有相似代码的页面 HTML CSS JS 之间的样式不同

javascript - Twitter widgets.js 在 IE8 上抛出 JavaScript 错误 "Expected identifier"

javascript - IE 错误 "Unexpected call to method or property access. Line: 113 Char: 460 Code: 0"

html - 当我应用 HTML5 shiv 时,为什么我的 HTML5 标签没有在 IE8 中设置样式?

html - 位置绝对 iframe 不正确的宽度和高度

html - IE上的paypal按钮问题

Android 推出菜单

css - Ionic 3 如何在自定义 ionic 输入中垂直居中文本?

html - CSS - 使文本保持在响应图像上的同一位置