center one div above two other divs

↘锁芯ラ 提交于 2021-01-27 19:24:46

问题


I would like to achieve this situation: Align a div in center of page above 2 other divs

The page contains 4 divs in total. The main layer is divided in 3 divs. Above div1 and div2, another div(div4) must be floating above them in the middle of these 2 divs.

current code:

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;
}

I would appreciate it if anyone could give me a heads up.

Thanks in advance!


回答1:


If your issue is just how to get that layout this can help:

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

But this is just visual boxes, if you have more requirements can be a little tricky.



来源:https://stackoverflow.com/questions/28196741/center-one-div-above-two-other-divs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!