展开仅包含绝对位置图像的div高度

时间:2019-08-20 08:15:25

标签: css

.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容器的高度为min-height,但也可以扩展为aboutus__content容器。

我有点困惑为什么aboutus__imageWrapperheight: 100%不能扩展到其父aboutus的高度

1 个答案:

答案 0 :(得分:2)

从此规则中删除 overflow:hidden

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