CSS Floating with Overlap

后端 未结 4 1931
攒了一身酷
攒了一身酷 2021-02-01 03:33

I\'m trying to set up a simple horizontal tab structure for a page I\'m working on, and I\'m running into some trouble with floating div\'s combined with z-index.

Viewin

相关标签:
4条回答
  • 2021-02-01 03:58

    Use the position property for element upper. Adding position:relative to .left.

    0 讨论(0)
  • 2021-02-01 04:00

    z-index has no effect on elements that are not positioned (eg position:absolute;)

    0 讨论(0)
  • 2021-02-01 04:04

    z-index property will not apply to statically positioned elements. In order to use z-index the CSS must also include any position value other than static (ie relative, absolute, fixed).

    .left { float: left; width: 96px; background-color: red; border: 2px solid orange; z-index: 3; margin-right: -2px; position: relative; }
    .right { float: left; width: 396px; background-color: #09c; border: 2px solid green; z-index: 2; position: relative; }
    

    Will give you what you want I think. I added position: relative; and changed the z-index of the .left to 3 (from 2) and changed the z-index of .right to 2 (from 3).

    0 讨论(0)
  • 2021-02-01 04:09

    Negative margin-left?

    .right { float: left; width: 396px; background-color: #09c; border: 2px solid green; z-index: 3; margin-left: -5px;}
    
    0 讨论(0)
提交回复
热议问题