尽管示例未考虑引导程序,但我正在使用引导程序。
我需要的是section
延伸到背景图像的高度。
我已经建立了一个最小的示例,但是它似乎并未加载背景图片:
答案 0 :(得分:1)
因此,这与您采取的方法不同,我遵循了此示例CSS: How to set container size equal to background image size。但是,它不使用background-image
属性。我不确定这是否对您有必要。
HTML
<div class="wrap">
<img src="https://escolaeducacao.com.br/wp-content/uploads/2015/07/dna.jpg" />
<section class="content">
to be expanded to the size of the background image.
</section>
</div>
CSS
.wrap {
display: inline-block;
position: relative;
}
.wrap img + .content {
position: absolute;
top: 0;
left: 0;
}
将自动换行设置为position: relative
会导致设置为position: absolute
的子元素相对于该父元素定位自身