CSS DIV位置问题(带有绝对位置的2格)

时间:2018-11-12 14:40:05

标签: html css

我设置了2个具有某些背景的div,并且我想将div2设置为div 1,但是我不知道该怎么做,请帮忙。现在,div2在div1之上,并且div1在此网站上不可见。

.div1 {
      perspective: 100px;
      height: 100vh;
      overflow-x: hidden;
      overflow-y: auto;
      position: absolute;
      top: 0;
      left: 50%;
      right: 0;
      bottom: 0;
      margin-left: -51%;
    }
    
    .div2 {
      perspective: 100px;
      height: 100vh;
      overflow-x: hidden;
      overflow-y: auto;
      position: absolute;
      top: 0;
      left: 50%;
      right: 0;
      bottom: 0;
      margin-left: -51%;
    }
<div class='div1'>Some very important text...</div>
<div class='div2'>Not so important text...</div>

1 个答案:

答案 0 :(得分:0)

也许对您有帮助,我在top: 100%;上添加了div2

.div1 {
  perspective: 100px;
  height: 100vh;
  overflow-x: hidden;
  overflow-y: auto;
  position: absolute;
  top: 0;
  left: 50%;
  right: 0;
  bottom: 0;
  margin-left: -51%;
  background-color: red;
}

.div2 {
  perspective: 100px;
  height: 100vh;
  overflow-x: hidden;
  overflow-y: auto;
  position: absolute;
  top: 100%; /*Changed*/
  left: 50%;
  right: 0;
  bottom: 0;
  margin-left: -51%;
  background-color: blue;
}

.div1::-webkit-scrollbar { 
    display: none; 
}
 
.div2::-webkit-scrollbar { 
    display: none; 
}
<div class="div1">a</div>
<div class="div2">a</div>