Extend child div beyond container div

后端 未结 4 914
攒了一身酷
攒了一身酷 2020-12-17 08:39

I\'m trying to expand this div across with width of the browser. I\'ve read from here that you can use {position:absolute; left: 0; right:0;} to achieve that a

4条回答
  •  遥遥无期
    2020-12-17 09:15

    Parent to position:static, child to position:absolute or

    Parent to position:relative, child to position:fixed (with the fixed, never moving downside)

    Your left: 0; right:0; works with both of these solutions, just note that your child div will draw on top of any divs below it in code, no matter what the div's display property is set to. You will either have to add a padding-top value to the next div to compensate (simple example in jsfiddle), or another div underneath that has the same height behavior as the child (a much more elaborate example in codepen), which is probably not ideal, but works in simple html/css.

提交回复
热议问题