How an absolutely positioned element overlaps the following/next element without any z-index?

不打扰是莪最后的温柔 提交于 2019-12-10 17:54:28

问题


Please see my fiddle here.

I'm trying to understand how the absolutely positioned "red hexagon" icon overlaps the input/textarea element without a z-index ?

<style>
    .c-icon-error-a {
        height: 17px;
        width: 18px;
    }
    .c-icon-v2 {
        background-image: url("http://i.stack.imgur.com/RSjot.jpg");
        background-repeat: no-repeat;
        display: inline-block;
        height: 14px;
        vertical-align: middle;
        width: 14px;
    }
    .c-icon-error-a {
        margin: 4px;
        position: absolute;
    }
    ul li {
        margin-bottom:15px;
    }
</stlye>
<body>
        <ul>
        <li>
            <span class="c-icon-v2 c-icon-error-a"></span>
            <input type="text"   value="" id="Validation_Field1" name="Validation.Field1" />
        </li>
        <li>
            <span class="c-icon-v2 c-icon-error-a"></span>
            <textarea rows="5" cols="25" name="txtarea" id="txtarea"></textarea>
        </li>
    </ul>
</body>

Do the absolutely positioned elements have a separate z-index count which are higher than the elements occurring in normal flow ?


回答1:


Absolutely positioned items will automatically overlap non-absolute items as standard, even without a set z-index. To get around this you need to set a position for all items you don't want to overlap.

Either that or find another way of placing your red hexagon, such as setting it as a background.

Reference: http://www.w3.org/TR/CSS2/zindex.html




回答2:


Instead of placing image along with text box, set background-image of text box.

Here is the fiddle



来源:https://stackoverflow.com/questions/19515835/how-an-absolutely-positioned-element-overlaps-the-following-next-element-without

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