[英]How can i give height of the child element (img) to parent element(section)?
<section class="banner container">
<img
src="https://img-prod-cms-rt-microsoft-com.akamaized.net/cms/api/am/imageFileData/RE4H4vB?ver=d252&q=0&m=8&h=600&w=1600&b=%23FFFFFFFF&l=f&x=0&y=0&s=1898&d=712&aim=true"
alt=""
/>
<div class="explanation">
<h2>Xbox Game Pass Ultimate</h2>
In this code height of section looks as 0. But the height of img is 600px.在这段代码中,section 的高度看起来为 0。但 img 的高度是 600px。 How can i give the height of img to its parent element which is section?如何将 img 的高度赋予其父元素,即 section?
As you can see in the picture section class="banner container" has no height.正如您在图片部分看到的那样,class="banner container" 没有高度。
Please provide more of your code.请提供更多您的代码。 The code you provided is full of unclosed tags.您提供的代码中充满了未封闭的标签。 i assume your code should look like this:我假设您的代码应如下所示:
<section class="banner container">
<img
src="https://img-prod-cms-rt-microsoft-com.akamaized.net/cms/api/am/imageFileData/RE4H4vB?ver=d252&q=0&m=8&h=600&w=1600&b=%23FFFFFFFF&l=f&x=0&y=0&s=1898&d=712&aim=true"
alt=""/>
<div class="explanation">
<h2>Xbox Game Pass Ultimate</h2>
</div>
</section>
If you build it like that the section has the height of its containing children (img tag + h2 tag)如果您像这样构建它,则该部分具有其包含子项的高度(img 标签 + h2 标签)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.