两个固定元素(页眉和页脚)之间的Div

时间:2016-07-28 21:12:54

标签: html css position fixed

这就是我想要做的事情:

Layout illustration

我希望我已经用图片很好地解释了它。 我在这个主题上搜索了很多,但我真的不想进入大量的功能。我想尽可能简单地解决它。

问题是因为如果用户更改浏览器大小或在不同屏幕上显示,我希望所有人都能实时响应。

另外,关于在左侧菜单中添加这些图像;它们的比例为1:1,但我想将它们放在一起,它们将是左侧菜单的100%高度(蓝色图片)。

这是我到目前为止所做的:

HTML / CSS:

header {
   background-color: red;
   position: relative;
   width: 100%;
}

#allContents {
   position: relative; /*minus širina headerja in footerja!!*/
   height: 100%;
   width: 100%;
   float: left;
   clear: both;
   z-index: 10;
}

#leftMenu {
   position: relative;
   background-color: green;
   width: 10%;
   height: 100%;
   z-index:10; 
}

#mainContent {
   background-color: yellow;
   size: 20%;
   float: left;
   position: relative;
}

#rightMenu {
   background-color: orange;
   float: left;
   position: relative;
   top: 0;
   right: 0;
   width: 25%;
}

footer {
   clear: both;
   background-color: blue;
   position: fixed;
   bottom: 0px;
   width: 100%;
}
<header>
   Fixed. Some header content... also image on the left.
</header>

<div id="allContents">
   <div id="leftMenu">On left, between header and footer, but never behind. Always between.</div>
   <div id="mainContent">Between all 4 elements. Here will be main content with scrolling.</div>
   <div id="rightMenu">Div with some news.</div>
</div>

<footer>
   Fixed footer.
</footer>

2 个答案:

答案 0 :(得分:1)

听起来你会从使用Flexbox中获益匪浅。它们允许您使用CSS格式化您想要的确切结构,并且它们响应窗口大小。 Flexbox Froggy是学习如何使用它们的绝佳资源。

答案 1 :(得分:0)

你在找这个吗?

&#13;
&#13;
header {
   background-color: red;
   position: relative;
   width: 100%;
}

#allContents {
   position: relative; /*minus širina headerja in footerja!!*/
   height: 100%;
   width: 100%;
   float: left;
   clear: both;
   z-index: 10;
    display: -webkit-flex;
    display: flex;
}

#leftMenu {
   position: relative;
   background-color: green;
   width: 10%;
   height: 100%;
   z-index:10; 
 
}

#mainContent {
   background-color: yellow;
   size: 20%;
   float: left;
   position: relative;
 
}

#rightMenu {
   background-color: orange;
   float: left;
   position: relative;
   top: 0;
   right: 0;
   width: 25%;
  
}
&#13;
<header>
   Fixed. Some header content... also image on the left.
</header>

<div id="allContents">
   <div id="leftMenu">On left, between header and footer, but never behind. Always between.</div>
   <div id="mainContent">Between all 4 elements. Here will be main content with scrolling.</div>
   <div id="rightMenu">Div with some news.</div>
</div>

<footer>
   Fixed footer.
</footer>
&#13;
&#13;
&#13;

相关问题