html - 如何创建相对定位的页脚

标签 html css

我想像所有其他页脚一样制作页脚。深底并留在那里。但另一方面,我希望它的顶部可以根据 div.content 的位置进行扩展。它可能是像 10px 这样的常量值。因此,如果 div.content 移动到顶部,它就会移动到(同时仍将屏幕底部保持为页脚)。我该怎么做?

.main {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  margin: 0;
  width: 100%;
  height: 100%;
}
.content {
  position: relative;
  margin-left: 10%;
  margin-right: 10%;
}
.left-content {
  float: left;
  margin: 2.27272727272727%;
  /* 20/880 = 0.0227272727272727 */
  width: 56.81818181818182%;
  /* 500/880 = 0.5681818181818182 */
  background-color: aquamarine;
}
.right-content {
  float: left;
  margin: 2.27272727272727%;
  /* 20/880 = 0.0227272727272727 */
  width: 34.09090909090909%;
  /* 300/880 = 0.3409090909090909 */
  background-color: mediumturquoise;
}
.inner-content {
  float: left;
  margin: 2%;
  /* 10/500 = 0.02 */
  width: 44%;
  /* 220/500 = 0.44 */
  background-color: darkgreen;
}
.footer {
  clear: both;
  height: 10%;
  bottom: 0px;
  width: 100%;
  position: absolute;
  background-color: darkcyan;
}
<div class="main">
  <div class="content">
    <div class="left-content">
      <h1>A</h1>
      <p>asd</p>
      <p>asd</p>
      <p>asd</p>
      <p>asd</p>
      <p>asd</p>
      <div class="inner-content">
        <h1>D</h1>
      </div>
      <div class="inner-content">
        <h1>D</h1>
      </div>
    </div>
    <div class="right-content">
      <h1>B</h1>
      <p>asd</p>
      <p>asd</p>

    </div>
  </div>
  <div class="footer">
    <h1>C</h1>
  </div>
</div>

最佳答案

如果我对您的问题的理解正确,您无论如何都希望将页脚保留在屏幕底部。正确吗?

为此,将以下内容添加到您的页脚类。

    position: fixed;
    bottom: 0;

关于html - 如何创建相对定位的页脚,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38545278/

相关文章:

javascript - 在每个页面中使用嵌套 View 时,如何使用 ui-router 进行页面重定向?

javascript - 根据 jQuery 中子数据的嵌套父数据值

html - 如何在 Canvas 中夹环?

css - 将标签与按钮对齐

javascript - 变换函数和光标: pointer not working

jquery - 类更改后在 jQuery 中重新计算元素高度

javascript - 如何使用javascript更改html选择器的宽度

javascript - 找出该形式中哪个单词最长?

css - 用unicode字符替换复选框

php - 移动导航栏 Wordpress 神秘主题问题