html - height div 从上到下页面颜色问题

标签 html css height

我在这里搜索了一个回复,但我没有找到解决方案...

我对 div 高度有疑问。 我自己解释一下:我在页面顶部有一个菜单,其权重是固定的:50 像素。

我有一个 MainDiv,它是最小高度为 100% 的主要 div。我已经将 Height:100% 放到 html 和 body 中。我的问题是我的 MainDiv 的背景颜色没有从页面的顶部到底部。我知道这是因为我的菜单有一个固定的高度,但我不知道如何改变它..

html {
  height: 100%;
}

body {
    background-image: url('../../Images/fond2.jpg');
    background-size: cover;
    background-attachment:fixed;
    background-position: left top;
    margin: 0;
    height: 100%;
}

#menuBackground {
    background:#2f3036;
    text-align: center;
    width : 100%;
    height : 50px;
    display : relative;
}

#MainDiv{
    max-width:850px;
    min-height: 100%;
    margin: 0 auto;
    background-color:#E0CDA9;
    display : absolute;
    z-index: 10;
}

看看我的 fiddle 元素:http://jsfiddle.net/hr8sL/5925/

我只是想让背景颜色填充页面(当然没有顶部菜单)。

编辑:我尝试使用溢出:自动。它可以工作,但滚动条位于 div 上。我想在整个页面上保留滚动条。

最佳答案

试试这个:你在 #menuBackground {display : relative;} 中有一个错误。

将其更改为 #menuBackground {display : inline-block;}

关于html - height div 从上到下页面颜色问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42721644/

相关文章:

javascript - Vuejs 2.0 单文件组件、webpack 和 leaflet map

jquery - 数据表插件 : if not sortable remove text-decoration from column header

javascript - 为什么我的高度固定器代码在最大化后恢复浏览器窗口时出错?

javascript - 带有 javascript 代码的 iPhone 应用程序和 uiwebview 我可以访问变量吗?

html - 根据屏幕尺寸更改面板尺寸

html - div css3名称问题

html - 无法将 div 置于中心(边距 :0 auto; doesn't work)

javascript - 在新插件中使用 attr() 函数?

html - 在同一个元素上使用高度和边框是好习惯吗?

css - ie7 float div高度