当绝对div大于窗口主体时,不显示窗口滚动条

时间:2018-10-22 23:13:32

标签: html css

我很困惑,但是我一直在互联网上甚至在google上搜索这个主题,所以我通常会注意到当我的绝对div大于窗口时,它总是显示主要内容窗口主体中的滚动条,因此在这种情况下不这样做 enter image description here

那是为什么?

我该如何解决?

这是我的代码示例

.container {
    background-color: red;
	position: absolute;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	margin: auto;
	width: 80%;
	height: 500px;
	-webkit-box-sizing: border-box;
    box-sizing: border-box;
	overflow-y: auto;
	overflow-x: hidden;
}

.container .responsive {
    margin: 6px 0;
    padding: 0 6px;
    float: left;
    width: 16.66666%;
	
	-webkit-box-sizing: border-box;
            box-sizing: border-box;
}

.container .gallery {
    border: 1px solid #ccc;
	
	-webkit-box-sizing: border-box;
            box-sizing: border-box;
}

.container .gallery img {
    width: 100%;
    height: auto;
	
	-webkit-box-sizing: border-box;
            box-sizing: border-box;
}

@media (max-width: 1200px) { 

 .container .responsive {
        width: 16.66666% !important;
		
		-webkit-box-sizing: border-box;
            box-sizing: border-box;
    }
    
}

@media (max-width: 992px) { 
 .container .responsive {
        width: 24.99999% !important;
		-webkit-box-sizing: border-box;
            box-sizing: border-box;
    }
}

@media (max-width: 768px) { 
   .container .responsive {
        width: 49.99999% !important;
		-webkit-box-sizing: border-box;
            box-sizing: border-box;
    }
}

@media (max-width: 576px) { 
   .container .responsive {
        width: 100% !important;
		-webkit-box-sizing: border-box;
            box-sizing: border-box;
    }
}
<meta name="viewport" content="width=device-width">

<div class="container">

  <div class="responsive">
    <div class="gallery">
      <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/b/bc/Metolius_River_near_Wizard_Falls.jpg/1200px-Metolius_River_near_Wizard_Falls.jpg" alt="Cinque Terre" width="600" height="400">
    </div>
  </div>

  <div class="responsive">
    <div class="gallery">
      <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/b/bc/Metolius_River_near_Wizard_Falls.jpg/1200px-Metolius_River_near_Wizard_Falls.jpg" alt="Cinque Terre" width="600" height="400">
    </div>
  </div>

  <div class="responsive">
    <div class="gallery">
      <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/b/bc/Metolius_River_near_Wizard_Falls.jpg/1200px-Metolius_River_near_Wizard_Falls.jpg" alt="Cinque Terre" width="600" height="400">
    </div>
  </div>

  <div class="responsive">
    <div class="gallery">
      <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/b/bc/Metolius_River_near_Wizard_Falls.jpg/1200px-Metolius_River_near_Wizard_Falls.jpg" alt="Cinque Terre" width="600" height="400">
    </div>
  </div>

  <div class="responsive">
    <div class="gallery">
      <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/b/bc/Metolius_River_near_Wizard_Falls.jpg/1200px-Metolius_River_near_Wizard_Falls.jpg" alt="Cinque Terre" width="600" height="400">
    </div>
  </div>

  <div class="responsive">
    <div class="gallery">
      <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/b/bc/Metolius_River_near_Wizard_Falls.jpg/1200px-Metolius_River_near_Wizard_Falls.jpg" alt="Cinque Terre" width="600" height="400">
    </div>
  </div>

  <div class="responsive">
    <div class="gallery">
      <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/b/bc/Metolius_River_near_Wizard_Falls.jpg/1200px-Metolius_River_near_Wizard_Falls.jpg" alt="Cinque Terre" width="600" height="400">
    </div>
  </div>

  <div class="responsive">
    <div class="gallery">
      <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/b/bc/Metolius_River_near_Wizard_Falls.jpg/1200px-Metolius_River_near_Wizard_Falls.jpg" alt="Cinque Terre" width="600" height="400">
    </div>
  </div>

  <div class="responsive">
    <div class="gallery">
      <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/b/bc/Metolius_River_near_Wizard_Falls.jpg/1200px-Metolius_River_near_Wizard_Falls.jpg" alt="Cinque Terre" width="600" height="400">
    </div>
  </div>

  <div class="responsive">
    <div class="gallery">
      <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/b/bc/Metolius_River_near_Wizard_Falls.jpg/1200px-Metolius_River_near_Wizard_Falls.jpg" alt="Cinque Terre" width="600" height="400">
    </div>
  </div>
  
</div>

0 个答案:

没有答案