html - 页脚宽度问题

标签 html css


我这里有点问题。我有以下 CSS 代码:

body
{
    margin: 0 0 200px; //Same height of the footer
}
div.content
{
    display: table;
    margin: 0 auto;
}
div.main-content
{
    margin: 20px 10px;
    text-align: left;
    background-color: rgba(255, 255, 255, 0.95);
    -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
    border-radius: 5px;
    padding: 15px;
    -webkit-box-shadow: 0px 4px 5px 0px rgba(0,0,0,0.75);
    -moz-box-shadow: 0px 4px 5px 0px rgba(0,0,0,0.75);
    box-shadow: 0px 4px 5px 0px rgba(0,0,0,0.75);
}
footer
{
    position: absolute;
    left: 0;
    bottom: 0;
    height: 200px;
    width: 100%;
    overflow: auto;
    background-color: rgba(67, 191, 115, 0.95);
}

通过这种方式,在我使用的所有页面中:

<div class='content'>
    <div class='main-content'>
        //Page content goes here
    </div>
</div>
<footer>
    //Footer content goes here
</footer>

我的问题是,如果分辨率低于内容,页脚就不会保持页面的宽度,变成这样: enter image description here

我也创建了这个显示问题的 fiddle :http://jsfiddle.net/pmb1vbdh/1/
看到页脚如何不随表格展开并留有空白吗? 我该如何解决这个问题?谢谢!

最佳答案

它有效。检查这个。

div.content
{
    display: table;
    margin: 0 auto;
}
div.main-content
{
    margin: 20px 10px;
    text-align: left;
    background-color: rgba(255, 255, 255, 0.95);
    -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
    border-radius: 5px;
    padding: 15px;
    -webkit-box-shadow: 0px 4px 5px 0px rgba(0,0,0,0.75);
    -moz-box-shadow: 0px 4px 5px 0px rgba(0,0,0,0.75);
    box-shadow: 0px 4px 5px 0px rgba(0,0,0,0.75);
}
footer
{
    position: absolute;
    left: 0;
    bottom: 0;
    height: 200px;
    width: 100%;
    overflow: auto;
    background-color: rgba(67, 191, 115, 0.95);
}
<div class='content'>
    <div class='main-content'>
        //Page content goes here
    </div>
</div>
<footer>
    //Footer content goes here
</footer>

编辑其他人回答中的评论;

demo

关于html - 页脚宽度问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30289281/

相关文章:

php - 标题图片造成巨大差距

html - 如何在 Angular 2 中轻轻更改 img src

css - 创建伪元素,但排除特定元素(不包含 :nth-child)

html - 边框左右两侧有多余的空间,我该如何解决?

html - CSS 打字效果不起作用

css - 如何在 twitter bootstrap 中使用只有字形的按钮

css - 移动屏幕尺寸的复选框(输入)高度和宽度发生变化?

jquery - 当另一个 div 悬停在 jQuery 上时,div 下拉

jquery - 属性(对齐)已过时。不鼓励在 HTML5 文档中使用它

javascript - 如何设置固定位置元素高度到达浏览器窗口底部?