html - 将一个 div 置于另外两个 div 之上

标签 html css css-position

我想实现这种情况: Align a div in center of page above 2 other divs

该页面总共包含 4 个 div。主层分为 3 个 div。 在 div1 和 div2 上方,另一个 div(div4) 必须 float 在这 2 个 div 的中间。

当前代码:

body {
position:relative;
}

div1 {
 // nothing
}

div2 {
 // nothing
}

div3 {
 // nothing
}

div4 {
 z-index: 10;
 position: absolute;
 top: 550px;
 left: 0;
 margin-left: auto;
 margin-right: auto;
 width: 50%;
 padding: 50px;
}

如果有人能给我提示,我将不胜感激。

提前致谢!

最佳答案

如果您的问题只是如何获得该布局,这可以提供帮助:

* {
  margin: 0
}
html,
body {
  height: 100%;
}
div {
  height: 33.3%;
}
.one {
  background: red;
}
.two {
  background: green;
}
.three {
  background: blue;
}
.four {
  position: absolute;
  background: yellow;
  top: 17%;
  left: 30%;
  width: 40%;
}
<div class="one"></div>
<div class="two"></div>
<div class="three"></div>
<div class="four"></div>


但这只是视觉框,如果您有更多要求可能会有点棘手。

关于html - 将一个 div 置于另外两个 div 之上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28196741/

相关文章:

html - 更具体的 css 绝对定位元素不会覆盖先前设置的高度/宽度

javascript - 在 jsp 中显示来自 servlet 的范围的动态单元格颜色

javascript - 如何用刻度包裹 D3 标签

php - 如何使用 Header 滚动到特定 ID?

chrome 中的 css 填充问题(但 firefox 中没有)

html - 我的 CSS 定位不稳定。我怎样才能稳定它?

html - 如何相对于内部绝对高度调整相对div高度?

javascript - 如何从 webpack 中的 Assets url 中删除后缀斜杠 "/"| Gatsby

javascript - 切换按钮时如何更改文本颜色?

html - 使用 RTL 方向时切换侧边栏