What's the difference between HTML's and CSS's width attribute?

后端 未结 7 1937
走了就别回头了
走了就别回头了 2020-11-29 07:49

The codes can be found here:

http://www.w3schools.com/css/tryit.asp?filename=trycss_float_elements




&l         


        
相关标签:
7条回答
  • 2020-11-29 08:32

    It's depends from browser engine, but difference is about this:

    If the part of HTML page with image is visible.

    Then you add width and height attributes to img tag the browser will know some(not final) image size before image is loaded and will add it native cap for images with images size. So browser will add some space(for image) on HTML page.

    If the part of HTML page with image is not visible.

    Then you add width and height attributes to img tag the browser will know some(not final) image size before image is loaded and can calculate for example offsetWidth or offsetHeight of image container right. Also width/height attributes will save you from image HTML container repaint if you don't crop image from css, because browser already add some space for image.

    0 讨论(0)
提交回复
热议问题