Resize a div element to its background image size

前端 未结 6 609
忘了有多久
忘了有多久 2021-01-04 11:24

Is it possible to make a

adapt to its background image? I mean to maintain the proportions width and height.

Clarification:

6条回答
  •  抹茶落季
    2021-01-04 11:57

    The easiest thing to do that doesn't need any javascript is to set your image as the background image and then make a .gif or a .png of the same size that you set as an overlay image in that div. That transparent .png or .gif will size the div. Transparent .png or .gif are only a couple of KB and your page will complete loading faster than with javascript.

    
    
        
        
        
        
            

提交回复
热议问题