几个小时后,我能够创建一个具有固定标题,动态内容高度和页脚始终位于(屏幕)底部的布局。以下是代码:https://jsfiddle.net/r56oqg41/
html {
height: 100%;
}
body {
margin: 0;
padding: 0;
height: 100%;
background: #DEDEDE;
}
#main {
display: flex;
min-height: 100%;
flex-direction: column;
}
#head {
width: 100%;
height: 40px;
border-bottom: 1px solid #115293;
background-color: #1976D2;
}
#head #head_content {
width: 600px;
padding: 6px;
color: #FFFFFF;
margin: 0 auto;
text-align: center;
}
#body {
flex: 1;
width: 600px;
margin: 0 auto;
background-color: #FFFFFF;
border-left: 1px solid #BFBFBF;
border-right: 1px solid #BFBFBF;
}
#body #menu {
float: left;
width: 150px;
padding: 10px;
background-color: #94C9FF;
border-right: 1px solid #BFBFBF;
}
#body #page {
overflow: hidden;
padding: 10px;
color: #5C5C5C;
}
#foot {
width: 100%;
height: 40px;
color: #FFFFFF;
border-top: 1px solid #115293;
background-color: #1976D2;
}
#foot #foot_content {
width: 600px;
padding: 6px;
margin: 0 auto;
text-align: center;
}
<div id="main">
<div id="head">
<div id="head_content">
HEADER
</div>
</div>
<div id="body">
<div id="menu">
MENU
</div>
<div id="page">
<p>PAGE CONTENT 01</p>
<p>PAGE CONTENT 02</p>
<p>PAGE CONTENT 03</p>
<p>PAGE CONTENT 04</p>
<p>PAGE CONTENT 05</p>
<p>PAGE CONTENT 06</p>
<p>PAGE CONTENT 07</p>
<p>PAGE CONTENT 08</p>
<!--
<p>PAGE CONTENT 09</p>
<p>PAGE CONTENT 10</p>
<p>PAGE CONTENT 11</p>
<p>PAGE CONTENT 12</p>
<p>PAGE CONTENT 13</p>
<p>PAGE CONTENT 14</p>
<p>PAGE CONTENT 15</p>
<p>PAGE CONTENT 16</p>
<p>PAGE CONTENT 17</p>
<p>PAGE CONTENT 18</p>
<p>PAGE CONTENT 19</p>
<p>PAGE CONTENT 20</p>
-->
</div>
</div>
<div id="foot">
<div id="foot_content">
FOOTER
</div>
</div>
</div>
问题是当没有内容时菜单的垂直边框(或#page
)保持隐藏...
我不希望页脚总是固定在底部。这取决于页面内容。
另一个问题是这个解决方案在IE11中不起作用(可能还有以下版本):(
请问,有没有办法始终显示垂直边框?
谢谢!
答案 0 :(得分:1)
body {
margin: 0;
padding: 0;
background: #DEDEDE;
}
#main {
display: flex;
flex-direction: column;
min-height: 100vh;
}
#head {
height: 40px;
border-bottom: 1px solid #115293;
background-color: #1976D2;
}
#head #head_content {
width: 600px;
padding: 6px;
color: #FFFFFF;
margin: 0 auto;
text-align: center;
}
#body {
flex: 1;
width: 600px;
margin: 0 auto;
background-color: #FFFFFF;
border-left: 1px solid #BFBFBF;
border-right: 1px solid #BFBFBF;
display: flex;
}
#body #menu {
width: 150px;
padding: 10px;
background-color: #94C9FF;
border-right: 1px solid #BFBFBF;
}
#body #page {
padding: 10px;
color: #5C5C5C;
}
#foot {
width: 100%;
height: 40px;
color: #FFFFFF;
border-top: 1px solid #115293;
background-color: #1976D2;
}
#foot #foot_content {
width: 600px;
padding: 6px;
margin: 0 auto;
text-align: center;
}
<div id="main">
<div id="head">
<div id="head_content">HEADER</div>
</div>
<div id="body">
<div id="menu">MENU</div>
<div id="page">
<p>PAGE CONTENT 01</p>
<p>PAGE CONTENT 02</p>
<p>PAGE CONTENT 03</p>
<p>PAGE CONTENT 04</p>
<p>PAGE CONTENT 05</p>
<p>PAGE CONTENT 06</p>
<p>PAGE CONTENT 07</p>
<p>PAGE CONTENT 08</p>
<p>PAGE CONTENT 09</p>
<p>PAGE CONTENT 10</p>
<p>PAGE CONTENT 11</p>
<p>PAGE CONTENT 12</p>
<p>PAGE CONTENT 13</p>
<p>PAGE CONTENT 14</p>
<p>PAGE CONTENT 15</p>
<p>PAGE CONTENT 16</p>
<p>PAGE CONTENT 17</p>
<p>PAGE CONTENT 18</p>
<p>PAGE CONTENT 19</p>
<p>PAGE CONTENT 20</p>
</div>
</div>
<div id="foot">
<div id="foot_content">FOOTER</div>
</div>
</div>
对于IE11支持,请参阅此帖子:flex property not working in IE
答案 1 :(得分:0)
这是因为div id="body"
的宽度大于屏幕的宽度。删除width: 600px;
和
#body{width:99%;}