Make child div stretch across width of page

后端 未结 12 691
鱼传尺愫
鱼传尺愫 2020-12-13 09:24

Suppose I have the following HTML code:

12条回答
  •  半阙折子戏
    2020-12-13 09:31

    Since position: absolute; and viewport width were no options in my special case, there is another quick solution to solve the problem. The only condition is, that overflow in x-direction is not necessary for your website.

    You can define negative margins for your element:

    #help_panel {
        margin-left: -9999px;
        margin-right: -9999px;
    }
    

    But since we get overflow doing this, we have to avoid overflow in x-direction globally e.g. for body:

    body {
        overflow-x: hidden;
    }
    

    You can set padding to choose the size of your content.

    Note that this solution does not bring 100% width for content, but it is helpful in cases where you need e.g. a background color which has full width with a content still depending on container.

提交回复
热议问题