简体   繁体   English

如何将子元素(img)的高度赋予父元素(部分)?

[英]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.

相关问题 如何为一个父级的子元素赋予比另一个父级更高的z索引? - How can I give a child element of one parent a higher z-index than another parent? 我该如何使用:不要将某些特定的 CSS 提供给父元素而不是子元素和子元素? - How can i use :not to give some specific CSS to parent element not to the child and sub-child? 为什么子元素 <img /> 父div的宽度和高度中不包含? - why child element <img /> not contains in the parent div width and height? CSS-如何防止子元素增加其父元素的高度,而是溢出? - CSS - How can I prevent a child element from increasing the height of it's parent, and instead overflow? 如何将样式应用于父元素和内联子元素? - How can I apply a style to a parent element and inline child element? 如何根据子元素值对父元素排序? - How can I sort a parent element based on child element value? 如果隐藏子元素,如何隐藏父元素? - How can I hide parent element if child element is hidden? 如何给我完整的身高元素?CSS - How can I give my full height element?CSS 父级div(未设置高度)是否将高度过大了几个像素以适合子img元素的高度? 为什么? - Parent div, height not set, over-sizes height by a few pixels to fit child img element height? Why? 如何在父元素和父元素的兄弟元素之上显示子元素? - How can I show child element above parent element AND siblings of the parent element?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM