隐藏的溢出不在图像上工作

时间:2018-04-24 14:44:36

标签: html css

我尝试过使用overflow:hidden;对于每个元素,但它似乎没有做任何事情

html看起来像这样,显示器是并排放置2个div(对于较小的屏幕堆叠在顶部)。左侧div也位于右侧div的顶部。我也有一个屏幕截图和小提琴。



.sec {
  background-color: red;
  min-height: 100vh;
  overflow: hidden;
}

.sec2 {
  background-color: blue;
  min-height: 100vh;
  overflow: hidden;
}

.img1 {
  max-width: 100%;
  position: absolute;
}

.img1 {
  z-index: 1;
}

.leftCol {
  z-index: 10;
  width: 50%;
}

.info-row {
  display: flex;
  flex-direction: row;
  margin-left: 10vw;
  margin-right: 200px;
}

.rightCol {
  width: 50%;
}

<section class="sec">
  <div class="info-row">
    <div class="leftCol info-column">
      <h1>haheaheh</h1>
      <p>teataetetat</p>
    </div>
    <div class='rightCol info-column'>
      <img class="img1" src='https://kasonbloom.files.wordpress.com/2017/08/lamb-2.jpg' />
    </div>
  </div>
</section>

<section class="sec2">
  <div class="info-row">
    <div class="leftCol info-column">
      <h1>asdfasdfasdf</h1>
      <p>basfbasdfbasdfba</p>
    </div>
    <div class='rightCol info-column'>
    </div>
  </div>
</section>
&#13;
&#13;
&#13;

enter image description here

https://jsfiddle.net/gtrnrd9r/2/将结果视图保留在图像突破

部分的位置

2 个答案:

答案 0 :(得分:1)

  

position:relative;添加到您的外部.sec,它会正常工作。

&#13;
&#13;
.sec {
  background-color: red;
  min-height: 100vh;
  overflow: hidden;
  position:relative;
}

.sec2 {
  background-color: blue;
  min-height: 100vh;
  overflow: hidden;
}

.img1 {
  max-width: 100%;
  position: absolute;
}

.img1 {
 z-index: 1;

}

.leftCol {
  z-index: 10;
  width: 50%;
}

.info-row {
  display: flex;
  flex-direction: row;
  margin-left: 10vw;
  margin-right: 200px;
}

.rightCol {
    width: 50%;
}
&#13;
<section class="sec">
  <div class="info-row">
    <div class="leftCol info-column">
      <h1>haheaheh</h1>
      <p>teataetetat</p>
    </div>
    <div class='rightCol info-column'>
      <img class="img1" src='https://kasonbloom.files.wordpress.com/2017/08/lamb-2.jpg' />
    </div>
  </div>
</section>

<section class="sec2">
  <div class="info-row">
    <div class="leftCol info-column">
      <h1>asdfasdfasdf</h1>
      <p>basfbasdfbasdfba</p>

    </div>
    <div class='rightCol info-column'>
    </div>
  </div>
</section>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

如果我没弄错的话,

.rightCol需要自己的宽度和高度。溢出不适用于父元素。