首页 > 解决方案 > 展开仅包含具有绝对位置的图像的 div 高度

问题描述

.aboutus {
  width: 100%;
  min-height: 334px;
}

.aboutus__content {
  z-index: 1;
  position: relative;
  color: orange;
  max-width: 1800px;
  margin: 0 auto;
}

.aboutus__imageWrapper {
  width: 100%;
  height: 100%;
  overflow: hidden;
  z-index: 0;
  position: relative;
}

img {
  position: absolute;
  height: auto;
  width: 100%;
  z-index: 0;
  bottom: 0;
  right: 0;
}
<div class='wrapper'>
  <div class='aboutus'>
    <div class='aboutus__content'>
      <p>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
      </p>
      <p>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
      </p>
      <p>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
      </p>
    </div>
    <div class='aboutus__imageWrapper'>
         <picture>
          <!-- Media query images go here -->
          <img src='https://www.visitmosselbay.co.za/wp-content/gallery/mossel-bay-photo-gallery/Mossel-Bay-Cape-St-Blaize-Lighthouse.jpg'>
        </picture>
    </div>
  </div> 
</div>

这个想法是使图像与aboutus容器的高度相匹配。虽然aboutus容器高度有最小高度,也可以扩展但aboutus__content容器。

我有点困惑为什么aboutus__imageWrapperwithheight: 100%没有扩展到它的父级的高度aboutus

标签: css

解决方案


从此规则中删除溢出:隐藏:

.aboutus__imageWrapper {
    width: 100%;
    height: 100%;
    overflow: hidden;
    z-index: 0;
    position: relative;
}

推荐阅读