Div background image proportional scaling

write in front

The active page background uses a div as a container for cutting images (it is more convenient to adjust and change than img)

Encountered a problem with proportional scaling.
 

Solution

Use padding-bottom

Because we are simply doing the background, we can use the properties of the padding percentage relative to the width

Change the height to padding-bottom and the
aspect ratio is width: padding-bottom
 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324910462&siteId=291194637