gpt4 book ai didi

html - 如何使用 CSS 获得以下页面布局?

转载 作者:行者123 更新时间:2023-11-28 12:22:42 26 4
gpt4 key购买 nike

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

Page demonstration: header, menu, submenu to left, main content area, and footer

这是我试过的代码:

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>

这是一个 live demonstration在 JS Fiddle 上。

最佳答案

解决此问题的最佳方法是为页眉、侧边栏和页脚固定 div。然后是插入主体使其可滚动的一个主要 div。您(至少我是这样)想要原生滚动并且应该避免设置高度的可滚动 div。

与使用可滚动内容 div 相比插入主体的好处:

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

我是这样解决的:

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

关于html - 如何使用 CSS 获得以下页面布局?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18756775/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com