The problem of aspect ratio in css

< div id=box >

<img src="">

< / div >

< H1 > box {< / H1 >
overflow: hidden
height: 0
padding-bottom: 43.372rem

}
at present, the width and height of 1rem = 50px pictures are 640276 respectively. How is the value of the aspect ratio padding-bottom calculated

Apr.11,2021

according to the title and description, you want the aspect ratio of the box to be equal to 640 container 276 of the picture, then the padding-bottom should use the percentage, whose actual pixel value reference is the parent container width of the image. In this case, the value of padding-bottom should be 276 over 640 * 100% = 43.125%

actual dom structure


        <img/>
    </div>
</div>
Menu