Why is overflow interacting with z-index?

前端 未结 4 1758
挽巷
挽巷 2021-02-12 20:28

I am trying to understand the rules behind z-index and how it interacts with the overflow property.

I have this html:


  
4条回答
  •  失恋的感觉
    2021-02-12 21:31

    The Parent Class cell need to be set it's height. because height of absolute element doesn't affect it;s parent.

     .boxy {
          position: absolute;
          z-index: 9999;
          top:70px;
          width: 50px;
          height: 50px;
          background: #0FF;
    
        }
    
        .cell {
          border: 2px solid #F00;
          position: relative;
    
          /* comment these two lines out and the box appears */
          /* or change them both to 'visible' */
          /* changing only one of them to 'visible' does not work */
          overflow-y: auto;
          overflow-x: auto;
          min-height: 120px; /* height 70px(Top)+50px*/
        }
    

提交回复
热议问题