0

我希望我的布局如下图所示

页面演示:页眉、菜单、左侧子菜单、主要内容区域和页脚

这是我尝试过的代码:

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>&copy; 2013. 123India. All rights reserved.</p>
            </div>
        </div>
    </form>
</body>

这是 JS Fiddle 的现场演示

4

1 回答 1

0

处理这个 imo 的最佳方法是为页眉、侧边栏和页脚固定 div。然后是一个主 div,它推动身体使其可滚动。你(至少我愿意)想要原生滚动,并且应该避免设置高度的可滚动 div。

推送正文而不是使用可滚动内容 div 的好处:

  • 整个文档是可滚动的,而不仅仅是内容 div
  • 您不会遇到 -webkit-overflow-scrolling 的问题:触摸以及随之而来的任何硬件加速问题(例如,滚动窗格上相对定位的元素、图像撕裂……)

这是我解决它的方法:

<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
}

工作示例:

http://jsfiddle.net/kevinsmets/d5bpL/

于 2013-09-13T11:35:05.890 回答