![](/img/trans.png)
[英]How can I give a child element of one parent a higher z-index than another parent?
[英]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>
在這段代碼中,section 的高度看起來為 0。但 img 的高度是 600px。 如何將 img 的高度賦予其父元素,即 section?
正如您在圖片部分看到的那樣,class="banner container" 沒有高度。
請提供更多您的代碼。 您提供的代碼中充滿了未封閉的標簽。 我假設您的代碼應如下所示:
<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>
如果您像這樣構建它,則該部分具有其包含子項的高度(img 標簽 + h2 標簽)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.