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

2024-05-04

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

<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>

我已经搜索并尝试了我能想到的一切。也许我应该放弃使用按钮元素:-/

这里发生了什么?


您需要向按钮 css 添加溢出:可见。

这是一个小提琴https://jsfiddle.net/innerurge1/os2e9c2j/7/ https://jsfiddle.net/innerurge1/os2e9c2j/7/。另外,您应该用 span 替换 div,因为这更具语义性。按钮中不允许使用 Div,因为它们是块元素,而按钮是内联的。

.parent{
    position: relative;
    width: 200px;
    height: 200px;
    border: 0;
    background: gray;
    text-align : left;
    overflow:visible;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

按钮元素内的 IE8 绝对定位元素是错误的 的相关文章