Placing absolute behind relative positioned element

后端 未结 3 1599
离开以前
离开以前 2021-01-07 16:32

I have two elements in the same container, the first has position: absolute, the second position: relative. Is there a way to set the \"z-index\" o

相关标签:
3条回答
  • 2021-01-07 16:37

    CSS has a z-index property so on your nav#mainNav > img selector just set z-index: -1;. Here is a working jsFiddle: http://jsfiddle.net/8eLJz/1/

    0 讨论(0)
  • 2021-01-07 16:55

    http://jsfiddle.net/8eLJz/3/

    nav#mainNav > img {
        z-index: -1;
    }
    
    0 讨论(0)
  • 2021-01-07 16:58

    I'm not sure which one you want in front, but you just need to set position on both and set z-index on both. http://jsfiddle.net/8eLJz/2/

    a {
        color: black;
    }
    
    nav#mainNav {
        position: relative;
    }
    
    nav#mainNav > img {
        position: absolute;
        width: 100px;
        left: 0;
        z-index: 5;
    }
    
    nav#mainNav > a > img {
        width: 100%;
    }
    
    nav#mainNav > nav {
        width: 100%;
        position: relative;
        z-index: 10;
    }
    
    nav#mainNav > nav > a {
        display: block;
        text-align: right;
        background-color: yellow;
    }
    
    0 讨论(0)
提交回复
热议问题