问题
I would like to achieve this situation:
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