我希望我的布局如下图所示
这是我尝试过的代码:
CSS
body {
margin: 0;
padding: 0;
background-color: #faf8f6;
font-family:'Segoe UI', Verdana, Arial;
font-size: 13px;
color: #2c2c2c;
}
img, img a, img a:hover {
border: none;
}
p {
margin: 0;
padding: 0;
}
#main-wrapper {
margin: 0;
padding: 0;
width: 100%;
min-height: 100%;
position: fixed;
}
#header {
margin: 0;
padding: 0;
width: 100%;
height: 100px;
background-color: #faf8f6;
}
#left-logo {
margin: 38px 0 26px 35px;
width: 300px;
height: 36px;
float: left;
}
#left-logo p {
font-size: 32px;
color: #000000;
text-align: left;
line-height: 26px;
}
#left-logo p span {
color: #d4102b;
font-weight: bold;
}
#right-logo {
margin: 15px 35px 15px 0;
width: 217px;
height: 70px;
float: right;
}
#menu-wrapper {
margin: 0;
padding: 0;
width: 100%;
height: 28px;
background-color: #948e8a;
border-top: 1px solid #5a4736;
border-bottom: 1px solid #5a4736;
}
#body-wrapper {
top: 130px;
bottom: 25px;
width: 100%;
position: fixed;
}
#left-menu-wrapper {
width: 199px;
height: 100%;
float: left;
background-color: #948e8a;
border-right: 1px solid #5a4736;
}
#content-wrapper {
width: calc(100%-200px);
margin: 0 0 0 200px;
height: 100%;
}
#footer {
bottom: 0;
height: 24px;
width: 100%;
background-color: #948e8a;
border-top: 1px solid #5a4736;
position: fixed;
}
#footer p {
margin: 0 35px 0 0;
text-align: right;
line-height: 24px;
color: #ffffff;
font-size: 12px;
}
HTML
<body>
<form id="form1" runat="server">
<div id="main-wrapper">
<div id="header">
<div id="left-logo">
<p><span>123</span> India</p>
</div>
<div id="right-logo">
<img src="Css/Images/logo.gif" />
</div>
<div class="clr"></div>
</div>
<div id="menu-wrapper"></div>
<div id="body-wrapper">
<div id="left-menu-wrapper"></div>
<div id="content-wrapper"> </div>
</div>
<div id="footer">
<p>© 2013. 123India. All rights reserved.</p>
</div>
</div>
</form>
</body>
这是JS Fiddle的live demonstration。
答案 0 :(得分:0)
关于这个imo的最佳方法是标题,侧边栏和页脚的固定div。然后一个主要的div推动身体使其可滚动。你(至少我)想要原生滚动,并且应该避免设置高度的可滚动div。
推动身体而不是使用可滚动内容div的好处:
以下是我如何解决它:
<div id="header">head</div>
<div id="header2">head2</div>
<div id="sidebar">side</div>
<div id="content">
1st that's a lotta stuff!<br />that's a lotta stuff!<br />that's a lotta stuff!<br />that's a lotta stuff!<br />that's a lotta stuff!<br />that's a lotta stuff!<br />that's a lotta stuff!<br />that's a lotta stuff!<br />that's a lotta stuff!<br />that's a lotta stuff!<br />that's a lotta stuff!<br />that's a lotta stuff!<br />that's a lotta stuff!<br />that's a lotta stuff!<br />that's a lotta stuff!<br />that's a lotta stuff!<br />that's a lotta stuff!<br />that's a lotta stuff!<br />that's a lotta stuff!<br />that's a lotta stuff!<br />that's a lotta stuff!<br />that's a lotta stuff!<br />that's a lotta stuff!<br />that's a lotta stuff!<br />that's a lotta stuff!<br />that's a lotta stuff!<br />that's a lotta stuff!<br />that's a lotta stuff!<br />that's a lotta stuff!<br />that's a lotta stuff!<br />that's a lotta stuff!<br />that's a lotta stuff!<br />that's a lotta stuff!<br />that's a lotta stuff!<br />that's a lotta stuff!<br />that's a lotta stuff!<br />that's a lotta stuff!<br />
</div>
<div id="footer">foot</div>
对于css:
body, html{
margin: 0
}
#header, #header2, #sidebar, #footer{
border: 1px solid black;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
position: fixed;
left: 0
}
#header, #header2, #footer{ right: 0 }
#header {
background-color: lightblue;
height: 100px
}
#header2 {
background-color: lightyellow;
border-top-width: 0;
height: 30px;
top: 100px
}
#sidebar {
background-color: lightgreen;
border-top-width: 0;
border-bottom-width: 0;
top: 130px;
width: 200px;
bottom: 30px
}
#content {
padding-left: 200px;
padding-top: 130px;
padding-bottom: 30px
}
#footer {
background-color: lightgrey;
bottom: 0;
height: 30px
}
工作示例: