Expand body element width beyond width of window

谁说胖子不能爱 提交于 2019-11-30 09:21:18
Iqbal

I just added following CSS. And it works.

body {
    float: left;
    min-width: 100%;
}

This isn't a solution to exactly the question you asked, but a neat option would be to add overflow:auto to #main, so it can scroll internally without breaking the layout.

#main {
    overflow: auto;
}

Demo: http://jsfiddle.net/dZS4V/

This is an approach:

#wideContent {
    background: #FF0;
    width: 4800px; /* In reality, this will vary at runtime, so I cannot set an explict width on the body */
    max-width: 100%;
}

The wideContent div will adjust to the width of the window.

After further fiddling, I've come up with a solution which involves adding an additional wrapper element to the three section elements. This may be useful to others with the same problem, however, I'm not going to mark this as accepted (yet) because I'm still keen to see if there's a CSS solution which doesn't involve modifying the HTML at all.

Anyway, this solution is to wrap the header, footer and div#main elements in a new div.layout-row element and add the following CSS:

    body {
        display: table;
        border-spacing: 0;
        min-width: 100%;
        box-sizing: border-box; /* Only needed if your body has padding or borders */
        margin: 0;
    }

    div.layout-row {
        display: table-row;
    }

    header, footer, div#main {
        display: table-cell;
    }

Seems to work in Chrome, FF and IE. Demo here.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!