【问题标题】:CSS White Space At Bottom of Page页面底部的 CSS 空白
【发布时间】:2015-04-09 06:18:44
【问题描述】:

如何消除页面底部的空间?

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

【问题讨论】:

  • 试过html, body { height: 100%; margin: 0; padding: 0; } ?
  • 很难理解您的要求。您能否简化示例代码并更清楚地传达您遇到的问题? “底部的这个空间”不是很具有描述性。什么空间?您是指页脚和浏览器窗口底部之间的空间吗?
  • 尝试编辑 OP 帖子以共享此图像,但由于“代码错误过多”而无法共享。这是他的问题的样子:i.imgur.com/YuF3BWc.png

标签: html css removing-whitespace


【解决方案1】:

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

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

保证金崩溃的解释

您已将div#pageTop 设置为position:fixed,并将margin-top:100px 添加到div#pageMain 以将其向下推到固定标题下方。该边距与 div#pageWrapper 并最终与 &lt;body&gt; 一起折叠。

由于&lt;body&gt; 设置为height:100% 并且折叠边距将其向下推100px,&lt;body&gt; 最终会高100px 并导致浏览器中出现垂直滚动条。 100% + 100px 的高度总是大于窗口的高度,并且总是需要滚动条。

下面是显示&lt;body&gt; 顶部的图像。请注意,它没有按预期从页面顶部开始。它开始向下 100px,在标题下方:

如何修复折叠边距

several methods 可以防止边距折叠。在这种情况下,我建议将div#pageMain 上的margin-top:100px 更改为填充:

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

这会阻止页边距折叠并将&lt;body&gt; 带回到它所属的窗口顶部:

现在&lt;body&gt; 的高度是窗口的 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>

【讨论】:

  • 感谢您更好地解释它,我也做了您建议的更改!
【解决方案2】:

这是因为你有身高:100%;在您的 html 和 body 标签上。此外,它在您的 pageWrapper 类上。这告诉浏览器无论如何都要使页面的高度至少等于视口的高度,然后告诉你的内部 pageWrapper 类无论如何都要匹配那个高度。

我建议制作 html height: auto;开始吧。

【讨论】:

  • 您所描述的如何在页面底部创建空白?
  • 因为你的pageWrapper类有视口的高度,大于页面上所有内容的高度。因此,如果没有足够的内容来填充页面,您将看到空白
  • 对不起,我想我是指他获得的额外空间,它导致出现滚动条。
  • 这很好用;我承认开头的 CSS 是从我很久以前制作的网站复制而来的。我有点懒,老天,我真的需要阅读现代 CSS XD
【解决方案3】:

div 类“问题”的高度为 2032 像素。在这个 div 下方是一个名为“answer”的 div,它是一个 728 X 870 像素的空白 div。可以通过缩小答案 div 以消除一些空白来消除空白。然而,一些空白是因为答案区域。要了解如何更改 CSS,请访问 http://www.w3schools.com/cssref/pr_dim_height.asp。查找这些 div 的代码位于 body、container、content、itemscope 和 mainbar 下。

【讨论】:

  • 您描述的&lt;div&gt; 元素是StackOverflow 结构的一部分,而不是OP 代码的一部分。
  • 是的,这就是页面底部有空间的原因。我把他的代码复制到一个 HTML 文档中。在谷歌浏览器中打开后,底部没有空白。导航栏按原意位于页面底部。
【解决方案4】:

我通过从您的 body 中删除 line-height:100% 来修复它。 加height:100vh给你#mainPage

#mainPage{
height:100vh;
}

【讨论】:

  • 也许你可以帮助澄清这个问题。你到底修了什么?你在解决什么问题?
  • 在 OP 的帖子/代码中,他的页脚从页面底部浮动了大约 1/3。他的line-height:100% 从底部向上推,添加height:100vh 使他的#mainPage 与浏览器窗口的高度相同。
  • 奇怪,我根本看不到页脚浮动。它正好靠在 sn-p 窗口的底部。您的意思是在“全屏”版本中,所有内容下方的空格?
  • @showdev 我在 2014 年 15" MacBook Pro 上,全页打开,运行 google chrome i.imgur.com/YuF3BWc.png
【解决方案5】:

我想也许你打算将黑色背景页脚部分放在底部,下面没有空白,对吧?您可以通过将页脚部分从页面包装器中取出,将其放在 end body 标记之前并添加此 css 来做到这一点:

对于 ID pageFooter 添加 css position:fixed;底部:0;

/* 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: 40px;
  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;
}

#footerContent h1 {
  position: absolute;
  right: 40%;
  font-size: 12px;
  color: #ccc;
}
#footerContent ul {
  padding: 0;
  margin: 0;
  margin-left: 20px;
}
#footerContent ul li {
  display: inline;
  line-height: 40px;
}

/*  ADD THIS TO FIX FOOTER TO BOTTOM  */
#pageFooter {
  position: fixed;
  bottom: 0;
}
<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>FIXED FOOTER &copy;2015 etc.</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>

【讨论】:

  • 请不要使用代码 sn-ps 除非你有真正“运行”的东西。
  • 代码 sn-p 非常简单,而且“确实有效”,所以我认为它可能会有所帮助。我已经继续并添加了带有固定页脚 css 的整个原始代码,好吧。
猜你喜欢
  • 2020-06-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多