gpt4 book ai didi

html - 页面底部的 CSS 空白

转载 作者:行者123 更新时间:2023-11-28 08:05:43 24 4
gpt4 key购买 nike

如何去掉页面底部的空格?

/* Basic Style */

html,
body {
height: 100%;
}
body {
background-color: #FFFFFF;
font-family: 'Roboto', sans-serif;
font-size: 12pt;
font-weight: 100;
color: #212121;
text-decoration: none;
line-height: 100%;
height: 100%;
margin: 0px 0px 0px 0px;
}
a:link {
color: #42b4da;
font-family: 'Roboto', sans-serif;
text-decoration: none;
}
a:visited {
color: #002946;
text-decoration: none;
}
a:active,
a:hover {
color: #670f08;
text-decoration: underline;
}
img {
border: 0px solid white;
margin: 0px;
padding: 0px;
}
.clear {
clear: both;
}
/* Text Formatting */

h1 {
font-size: 20pt;
color: #212121;
font-weight: lighter;
}
h2 {
font-size: 20pt;
color: #212121;
font-weight: lighter;
}
h3 {
font-size: 20pt;
color: #212121;
font-weight: lighter;
}
blockquote {
font-size: 12pt;
font-style: italic;
margin: 30px 30px 30px 0;
padding: 0 0 0 20px;
border-left: 1px solid #ccc;
}
/* Clear */

.clearBoth {
clear: both;
}
/* Page Wrapper*/

#pageWrapper {
width: 100%;
height: 100%;
}
/* Page Top */

#pageTop {
width: 100%;
height: 100px;
position: fixed;
top: 0;
left: 0;
z-index: 100;
overflow: hidden;
}
#topTitle {
background-color: #262626;
color: #CCCCCC;
width: 100%;
height: 100%;
float: left;
margin-right: -250px;
}
#topRight {
background-color: #262626;
color: #CCCCCC;
width: 250px;
height: 100%;
float: right;
}
/* Page Main */

#pageMain {
background: #ffffff url(../style/images/sidebarBackground.gif) repeat-y right;
width: 100%;
margin-top: 100px;
overflow: hidden;
}
/* Main Content */

#mainContent {
width: 100%;
height: 100%;
float: left;
margin-right: -250px;
}
.contentClear {
margin-right: 250px;
}
.contentPost {
margin: 40px;
}
.postTitle {} .postContent {} .postExtras {}
/* Main Sidebar */

#mainSidebar {
background: #262626 url(../style/images/sidebarBackground.gif) repeat-y right;
color: #CCCCCC;
width: 220px;
margin: 15px;
height: 100%;
float: right;
}
#mainSidebar h1 {
color: #CCCCCC;
font: 14pt'Roboto', sans-serif;
text-align: center;
margin: 2px;
padding: 2px;
}
#mainSidebar h1:before {
content: "‹";
position: relative;
left: -2px;
}
#mainSidebar h1:after {
content: "›";
position: relative;
left: 2px;
}
.sidebarContent {} .sidebarNav {
margin: 0;
padding: 0;
list-style: none;
}
.sidebarNav li:before {
content: "//";
position: relative;
left: 2px;
}
/* Page Footer */

#pageFooter {
width: 100%;
height: 100px;
overflow: hidden;
}
#footerContent {
background-color: #262626;
color: #CCCCCC;
width: 100%;
height: 100%;
float: left;
margin-right: -250px;
}
#footerRight {
background-color: #262626;
color: #CCCCCC;
width: 250px;
height: 100%;
float: right;
}
<div id="pageWrapper">
<div id="pageTop">
<div id="topTitle">
This is where the pages logo/title/whatever will go.
</div>
<div id="topRight">
Rightside content
</div>
</div>
<div class="clearBoth"></div>
<div id="pageMain">
<div id="mainContent">
<div class="contentClear">
<div class="contentPost">
<div class="postTitle">
<h1>HELLO WORLD!</h1>
</div>
<div class="postExtras">
<p>
APRIL 2, 2015 1 COMMENT
</p>
</div>
<div class="postContent">
<p>
Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!
</p>
<p>
This is the posts content; yeah!! This is the posts content; yeah!! This is the posts content; yeah!! This is the posts content; yeah!! This is the posts content; yeah!! This is the posts content; yeah!! This is the posts content; yeah!! This is the posts
content; yeah!! This is the posts content; yeah!! This is the posts content; yeah!! This is the posts content; yeah!! This is the posts content; yeah!! This is the posts content; yeah!!
</p>
</div>
</div>
</div>
</div>
<div id="mainSidebar">
<div class="sidebarContent">
<h1>Navigation</h1>
<ul class="sidebarNav">
<li>
<a href="_blank">Home</a>
</li>
<li>
<a href="_blank">About</a>
</li>
<li>
<a href="_blank">Contact</a>
</li>
<li>
<a href="_blank">Links</a>
</li>
</ul>
</div>
<div class="sidebarContent">
<h1>Unordered List</h1>
<ul>
<li>
Here is an unordered list in the sidebar.
</li>
<li>
Here is an unordered list in the sidebar.
</li>
<li>
Here is an unordered list in the sidebar.
</li>
<li>
Here is an unordered list in the sidebar.
</li>
</ul>
</div>
<div class="sidebarContent">
<h1>Something Else</h1>
<ol>
<li>
Here is an unordered list in the sidebar.
</li>
<li>
Here is an unordered list in the sidebar.
</li>
<li>
Here is an unordered list in the sidebar.
</li>
<li>
Here is an unordered list in the sidebar.
</li>
</ol>
</div>
</div>
</div>
<div class="clearBoth"></div>
<div id="pageFooter">
<div id="footerContent">
<h1>This is the footer, and copyright stuff.</h1>
<ul>
<li>
<a href="_blank">Home</a>
</li>
<li>
<a href="_blank">About</a>
</li>
<li>
<a href="_blank">Contact</a>
</li>
<li>
<a href="_blank">Links</a>
</li>
</ul>
</div>
<div id="footerRight">
<p>
SMLinks
</p>
</div>
</div>
</div>

最佳答案

如果我理解正确,问题是即使没有内容填充该滚动区域,也会有一个持续的垂直滚动条。

我相信这是由 "margin collapse" 引起的.

margin 暴跌的解释

您已设置 div#pageTopposition:fixed你已经添加了margin-top:100pxdiv#pageMain将其向下推到固定标题下方。该边距随着 div#pageWrapper 崩溃最终与 <body> .

<body>设置为 height:100%折叠边距将其向下推 100 像素,<body>最终会因为 100px 太高而导致浏览器出现垂直滚动条。 100% + 100px 的高度将总是大于窗口的高度并且总是需要滚动条。

下图显示了 <body> 的顶部.请注意,它不会按预期从页面顶部开始。它从标题下方 100px 开始:

enter image description here

如何修复折叠边距

several methods以防止边距坍塌。在这种情况下,我建议更改 margin-top:100pxdiv#pageMain进入填充:

#pageMain {
...
padding-top: 100px; /* padding instead of margin */
}

这会阻止边距崩溃并带来 <body>回到它所属窗口的顶部:

enter image description here

现在 <body> 的高度是 100% 的窗口,没有持久的滚动条。

请看下面的演示:

/* Basic Style */

html,
body {
height: 100%;
}
body {
background-color: #FFFFFF;
font-family: 'Roboto', sans-serif;
font-size: 12pt;
font-weight: 100;
color: #212121;
text-decoration: none;
line-height: 100%;
height: 100%;
margin: 0px 0px 0px 0px;
}
a:link {
color: #42b4da;
font-family: 'Roboto', sans-serif;
text-decoration: none;
}
a:visited {
color: #002946;
text-decoration: none;
}
a:active,
a:hover {
color: #670f08;
text-decoration: underline;
}
img {
border: 0px solid white;
margin: 0px;
padding: 0px;
}
.clear {
clear: both;
}
/* Text Formatting */

h1 {
font-size: 20pt;
color: #212121;
font-weight: lighter;
}
h2 {
font-size: 20pt;
color: #212121;
font-weight: lighter;
}
h3 {
font-size: 20pt;
color: #212121;
font-weight: lighter;
}
blockquote {
font-size: 12pt;
font-style: italic;
margin: 30px 30px 30px 0;
padding: 0 0 0 20px;
border-left: 1px solid #ccc;
}
/* Clear */

.clearBoth {
clear: both;
}
/* Page Wrapper*/

#pageWrapper {
width: 100%;
height: 100%;
}
/* Page Top */

#pageTop {
width: 100%;
height: 100px;
position: fixed;
top: 0;
left: 0;
z-index: 100;
overflow: hidden;
}
#topTitle {
background-color: #262626;
color: #CCCCCC;
width: 100%;
height: 100%;
float: left;
margin-right: -250px;
}
#topRight {
background-color: #262626;
color: #CCCCCC;
width: 250px;
height: 100%;
float: right;
}
/* Page Main */

#pageMain {
background: #ffffff url(../style/images/sidebarBackground.gif) repeat-y right;
width: 100%;
padding-top: 100px;
overflow: hidden;
}
/* Main Content */

#mainContent {
width: 100%;
height: 100%;
float: left;
margin-right: -250px;
}
.contentClear {
margin-right: 250px;
}
.contentPost {
margin: 40px;
}
.postTitle {} .postContent {} .postExtras {}
/* Main Sidebar */

#mainSidebar {
background: #262626 url(../style/images/sidebarBackground.gif) repeat-y right;
color: #CCCCCC;
width: 220px;
margin: 15px;
height: 100%;
float: right;
}
#mainSidebar h1 {
color: #CCCCCC;
font: 14pt'Roboto', sans-serif;
text-align: center;
margin: 2px;
padding: 2px;
}
#mainSidebar h1:before {
content: "‹";
position: relative;
left: -2px;
}
#mainSidebar h1:after {
content: "›";
position: relative;
left: 2px;
}
.sidebarContent {} .sidebarNav {
margin: 0;
padding: 0;
list-style: none;
}
.sidebarNav li:before {
content: "//";
position: relative;
left: 2px;
}
/* Page Footer */

#pageFooter {
width: 100%;
height: 100px;
overflow: hidden;
}
#footerContent {
background-color: #262626;
color: #CCCCCC;
width: 100%;
height: 100%;
float: left;
margin-right: -250px;
}
#footerRight {
background-color: #262626;
color: #CCCCCC;
width: 250px;
height: 100%;
float: right;
}
<div id="pageWrapper">
<div id="pageTop">
<div id="topTitle">
This is where the pages logo/title/whatever will go.
</div>
<div id="topRight">
Rightside content
</div>
</div>
<div class="clearBoth"></div>
<div id="pageMain">
<div id="mainContent">
<div class="contentClear">
<div class="contentPost">
<div class="postTitle">
<h1>HELLO WORLD!</h1>
</div>
<div class="postExtras">
<p>
APRIL 2, 2015 1 COMMENT
</p>
</div>
<div class="postContent">
<p>
Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!
</p>
<p>
This is the posts content; yeah!! This is the posts content; yeah!! This is the posts content; yeah!! This is the posts content; yeah!! This is the posts content; yeah!! This is the posts content; yeah!! This is the posts content; yeah!! This is the posts
content; yeah!! This is the posts content; yeah!! This is the posts content; yeah!! This is the posts content; yeah!! This is the posts content; yeah!! This is the posts content; yeah!!
</p>
</div>
</div>
</div>
</div>
<div id="mainSidebar">
<div class="sidebarContent">
<h1>Navigation</h1>
<ul class="sidebarNav">
<li>
<a href="_blank">Home</a>
</li>
<li>
<a href="_blank">About</a>
</li>
<li>
<a href="_blank">Contact</a>
</li>
<li>
<a href="_blank">Links</a>
</li>
</ul>
</div>
<div class="sidebarContent">
<h1>Unordered List</h1>
<ul>
<li>
Here is an unordered list in the sidebar.
</li>
<li>
Here is an unordered list in the sidebar.
</li>
<li>
Here is an unordered list in the sidebar.
</li>
<li>
Here is an unordered list in the sidebar.
</li>
</ul>
</div>
<div class="sidebarContent">
<h1>Something Else</h1>
<ol>
<li>
Here is an unordered list in the sidebar.
</li>
<li>
Here is an unordered list in the sidebar.
</li>
<li>
Here is an unordered list in the sidebar.
</li>
<li>
Here is an unordered list in the sidebar.
</li>
</ol>
</div>
</div>
</div>
<div class="clearBoth"></div>
<div id="pageFooter">
<div id="footerContent">
<h1>This is the footer, and copyright stuff.</h1>
<ul>
<li>
<a href="_blank">Home</a>
</li>
<li>
<a href="_blank">About</a>
</li>
<li>
<a href="_blank">Contact</a>
</li>
<li>
<a href="_blank">Links</a>
</li>
</ul>
</div>
<div id="footerRight">
<p>
SMLinks
</p>
</div>
</div>
</div>

jlane09 的回答也解决了这个问题。它具有有效性,因为它有效。但是,在我看来,这个答案并不能充分解释问题的原因。此外,使用 height:auto在某些情况下可能会导致更多问题(例如,对子元素使用基于百分比的高度)。


粘性页脚

创建“粘性”页脚是一个单独的问题。如果您希望无论窗口是否需要滚动,页脚始终贴在窗口底部,请参阅 Ryan Fait's (famous) sticky footer .它需要稍微不同的结构,但这是值得的。

我为您构建了一个基本演示,如下所示:

/* Basic Style */

html,
body {
height: 100%;
margin: 0;
}
/* Page Wrapper*/

#pageWrapper {
min-height: 100%;
height: auto !important;
height: 100%;
margin: 0 0 -160px;
}
/* Page Top */

#pageTop {
width: 100%;
height: 100px;
position: fixed;
top: 0;
left: 0;
z-index: 100;
}
#topTitle {
background-color: #262626;
color: #CCCCCC;
width: 100%;
height: 100%;
float: left;
margin-right: -250px;
}
#topRight {
background-color: #262626;
color: #CCCCCC;
width: 250px;
height: 100%;
float: right;
}
/* Page Main */

#pageMain {
background: #ffffff url(../style/images/sidebarBackground.gif) repeat-y right;
width: 100%;
padding-top: 100px;
}
/* Main Content */

#mainContent {
width: 100%;
height: 100%;
float: left;
margin-right: -250px;
}
.contentClear {
margin-right: 250px;
}
.contentPost {
margin: 40px;
}
.postTitle {} .postContent {} .postExtras {}
/* Main Sidebar */

#mainSidebar {
background: #262626 url(../style/images/sidebarBackground.gif) repeat-y right;
color: #CCCCCC;
width: 220px;
margin: 15px;
height: 100%;
float: right;
}
#mainSidebar h1 {
color: #CCCCCC;
font: 14pt'Roboto', sans-serif;
text-align: center;
margin: 2px;
padding: 2px;
}
#mainSidebar h1:before {
content: "‹";
position: relative;
left: -2px;
}
#mainSidebar h1:after {
content: "›";
position: relative;
left: 2px;
}
.sidebarContent {} .sidebarNav {
margin: 0;
padding: 0;
list-style: none;
}
.sidebarNav li:before {
content: "//";
position: relative;
left: 2px;
}
/* Page Footer */

#pageFooter {
width: 100%;
background-color: #262626;
}
#footerContent {
color: #CCCCCC;
width: 100%;
float: left;
margin-right: -250px;
}
#footerRight {
color: #CCCCCC;
width: 250px;
height: 100%;
float: right;
}
#pageFooter,
#footer_push {
height: 160px;
}
.clearfix:before,
.clearfix:after {
content: "";
display: table;
}
.clearfix:after {
clear: both;
}
.clearfix {
zoom: 1;
/* ie 6/7 */
}
<div id="pageWrapper">
<div id="pageTop">
<div id="topTitle">This is where the pages logo/title/whatever will go.</div>
<div id="topRight">Rightside content</div>
</div>
<div id="pageMain" class="clearfix">
<div id="mainContent">
<div class="contentClear">
<div class="contentPost">
<div class="postTitle">
<h1>HELLO WORLD!</h1>

</div>
<div class="postExtras">
<p>APRIL 2, 2015 1 COMMENT</p>
</div>
<div class="postContent">
<p>Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!</p>
<p>This is the posts content; yeah!! This is the posts content; yeah!! This is the posts content; yeah!! This is the posts content; yeah!! This is the posts content; yeah!! This is the posts content; yeah!! This is the posts content; yeah!! This
is the posts content; yeah!! This is the posts content; yeah!! This is the posts content; yeah!! This is the posts content; yeah!! This is the posts content; yeah!! This is the posts content; yeah!!</p>
</div>
</div>
</div>
</div>
<div id="mainSidebar">
<div class="sidebarContent">
<h1>Navigation</h1>

<ul class="sidebarNav">
<li> <a href="_blank">Home</a>

</li>
<li> <a href="_blank">About</a>

</li>
<li> <a href="_blank">Contact</a>

</li>
<li> <a href="_blank">Links</a>

</li>
</ul>
</div>
<div class="sidebarContent">
<h1>Unordered List</h1>

<ul>
<li>Here is an unordered list in the sidebar.</li>
<li>Here is an unordered list in the sidebar.</li>
<li>Here is an unordered list in the sidebar.</li>
<li>Here is an unordered list in the sidebar.</li>
</ul>
</div>
<div class="sidebarContent">
<h1>Something Else</h1>

<ol>
<li>Here is an unordered list in the sidebar.</li>
<li>Here is an unordered list in the sidebar.</li>
<li>Here is an unordered list in the sidebar.</li>
<li>Here is an unordered list in the sidebar.</li>
</ol>
</div>
</div>
</div>
<div id="footer_push"></div>
</div>
<div id="pageFooter">
<div id="footerContent">
<h1>This is the footer, and copyright stuff.</h1>

<ul>
<li> <a href="_blank">Home</a>

</li>
<li> <a href="_blank">About</a>

</li>
<li> <a href="_blank">Contact</a>

</li>
<li> <a href="_blank">Links</a>

</li>
</ul>
</div>
<div id="footerRight">
<p>SMLinks</p>
</div>
</div>

关于html - 页面底部的 CSS 空白,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29499997/

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