【问题标题】:Hidden overflow not working on image隐藏溢出不适用于图像
【发布时间】:2018-10-04 21:14:03
【问题描述】:

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

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>

https://jsfiddle.net/gtrnrd9r/2/ 将结果视图保留在图像突破该部分的位置

【问题讨论】:

  • 在您的 section CSS 中,minHeight 应该是 min-heightpaddingTop 应该是 padding-top。请尽量保持一致的缩进。
  • 我不确定你在哪里看到我有 minHeight 和 paddingTop,但我用整齐的缩进重新发布了小提琴
  • 我说的是您在此处发布的代码,而不是小提琴。 ;)
  • 哦,抱歉,我将它的前端反应样式转换为常规样式

标签: html css


【解决方案1】:

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

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

【讨论】:

  • 谢谢,我花了更多的时间来尝试解决这个问题
【解决方案2】:

.rightCol 如果我没记错的话,需要他自己的宽度和高度。溢出不适用于父元素。

【讨论】:

    猜你喜欢
    • 2013-12-16
    • 2021-05-20
    • 2020-03-28
    • 1970-01-01
    • 2018-04-14
    • 2023-03-27
    • 2017-02-23
    • 2014-02-28
    相关资源
    最近更新 更多