IE8 absolute positioned elements within button element are wrong

安稳与你 提交于 2019-12-10 10:16:13

问题


Title says it all: absolute positioned children of a button element are wrong in IE8
Here's a fiddle
And here's the mandatory piece of code:

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

I've searched and tried everything I could think of. Maybe I should abandon using the button element :-/

What's going on here?


回答1:


You need to add an overflow:visible to the button css.

Here is a fiddle https://jsfiddle.net/innerurge1/os2e9c2j/7/. Also you should swap out the divs with spans as this is more semantic. Divs are not "allowed" in buttons, because they are block elements and buttons are inline.

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


来源:https://stackoverflow.com/questions/14129550/ie8-absolute-positioned-elements-within-button-element-are-wrong

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!