html - CSS padding-bottom 似乎不起作用

标签 html css padding footer

我需要在固定页脚和页面底部之间留出空间。我已经尝试为 #main-content 设置填充,但它不起作用。这里有我没看到的问题吗?

enter image description here

CSS

#main-content {
    position: relative;
    width: 100%;
    padding-left:20px; 
    padding-right:20px;
    height: 300px; 

    box-sizing:border-box;
    padding-top: 50px; 
    padding-bottom: 200px;    
}

footer {
    background-color: #00496b;
    width: 100%;
    bottom: 0;
    position: fixed;
}

主要内容没有得到预期的结果,而是消失在页脚后面。我希望 #main-content 更进一步。希望我已经充分解释了这个问题。

最佳答案

在此 CSS 代码中:

#main-content {
    position: relative;
    width: 100%;
    padding-left:20px; 
    padding-right:20px;
    height: 300px;
    box-sizing:border-box;
    padding-top: 50px; 
    padding-bottom: 200px;    
}

您为 #main-content 设置了固定高度,因此 padding-bottom 无效。删除 height: 300px; 属性或将 300px 替换为 auto

CSS 代码应该是这样的:

#main-content {
    position: relative;
    width: 100%;
    padding-left:20px; 
    padding-right:20px;
    height: auto;  //height is set to auto
    box-sizing:border-box;
    padding-top: 50px; 
    padding-bottom: 200px;    
}

现在,padding-bottom 属性应该起作用了。让我知道这有帮助:)

关于html - CSS padding-bottom 似乎不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43154804/

相关文章:

html - 子div影响父div?

javascript - 如何使阅读项目在滚动时保持在同一位置

html - DIV 元素中图像后的额外空间

java - 如何在javafx中设置单个BorderPane区域的填充

css - <br> 元素的默认高度是多少?

javascript - html 表单 - `required` 属性未通过 onclick 确认触发

javascript - Mootools - IE 中的范围问题

javascript - 更改 Accordion 菜单插件中的链接

css - 转换:iOS 8 Mobile Safari 上的透视图 (#) 出现故障并隐藏元素

css - 使用边框折叠时顶部填充不适用于表格