How can I get an absolutely-positioned div to extend outside its relativley-positioned parent, which has overflow: auto?

前端 未结 8 626
栀梦
栀梦 2021-02-01 14:53

I have a relatively -positioned div, which has overflow: auto set. Inside that, I have a div which acts as a sort of drop-down menu. I want the drop-down div to e

8条回答
  •  悲哀的现实
    2021-02-01 15:14

    You use absolute positioning of inner div to position it relative to the outer div, but you do not want its content to count as outer div content. To achieve that, you need to separate inner div position from inner div content. You can try to do that by putting contents into fixed div.

    
    
     Test 
    
    
    
    

    The trick is that fixed div w/o top/bottom/left/right specified will position itself at its "static" position, which seems to be what you need.

    You may have problems with z-order, but, from your explanation, you do want your "menu" to be above everything else. (I assume that it comes and goes). You will sure have problems printing the page - if there is more than one page, fixed element repeats itself.

    As jvenema pointed out, this won't work in IE6. :(

提交回复
热议问题