我想实现一个特定的布局,但当我try 这样做,它得到了所有的秩序.我希望它像这张照片一样.有人能帮忙吗?

img

body {
  margin: 0px;
}

.top {
  width: 100%;
  background-color: blue;
  height: 40px;
  color: white;
}

.content {
  margin-left: 100px;
  height: 100%;
}

.sidebar {
  width: 100px;
  position: fixed;
  height: 100%;
  background-color: red;
}

.footer {
  height: 40px;
  width: 100%;
  background-color: black;
}
<div class="sidebar"></div>

<div class="content">
  <div class="top">My website example</div>

  <p>I start here</p>
</div>

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

推荐答案

嗯,你的页脚上只漏了一些东西.如果你想让它在一个特定的位置,你应该使用position: absoluteposition: fixed,就像你在sidebar上使用的一样.并插入bottom: 0,表示您希望它位于底部,而不是顶部或右/左.

body {
  margin: 0px;
}

.top {
  width: 100%;
  background-color: blue;
  height: 40px;
  color: white;
}

.content {
  margin-left: 100px;
  height: 100%;
}

.sidebar {
  width: 100px;
  position: fixed;
  height: 100%;
  background-color: red;
}

.footer {
  height: 40px;
  width: 100%;
  background-color: black;
  position: absolute;
  bottom: 0;
}
<div class="sidebar"></div>
<div class="content">
  <div class="top">My website example</div>
  <p>
    I start here
  </p>
</div>
<div class="footer"></div>

Html相关问答推荐

正文不能填满浏览器100%的高度

希望平稳过渡到悬停状态

HTML,CSS-阻止按钮在单击时向上移动

用由文本制成的边框包围内容

四开将一个 qmd 文档中的单词链接到另一个 qmd 文档中的单词

如何在Rmarkdown中添加千位分隔符?

拨动switch 在重新加载时未重置

我正在使用 NVDA 并多次读取关闭按钮,但它的读取非常完美

重点/主动输入的概述问题

子 div 在父 div 中溢出

那边界从何而来?

如何为某些行具有 rowspan 的表的每个奇数行着色

如何使我的下拉菜单响应?

右对齐 bootstrap 导航项而不是下拉菜单

正确使用视频作为背景

另一个 flex 元素之间的 CSS 空间

如何向上移动图像并溢出图像的一部分而另一部分不溢出

让 Bootstrap 5 模式和背景占据父容器的宽度和高度,而不是全屏

CSS:如何在模糊的背景上剪切文本?

如何使文本显示在页眉/页脚之外?