how to specify image size in pixels

前端 未结 5 1186
忘掉有多难
忘掉有多难 2020-12-19 02:20

Quick question about specifying the size of images in pixels:

\"logo\"

相关标签:
5条回答
  • 2020-12-19 02:34

    I would continue to specify the size in pixels. You probably don't need to, but I think you're supposed to according to web standards. Specifying the size in pixels is definitely not going to hurt your code, so leave it there.

    0 讨论(0)
  • 2020-12-19 02:39

    I usually leave it out. As not often is the case I use <img> elements. But, it is better practice to place the width and height in the <img> tag so the browser doesn't have to calculate these dimensions.

    0 讨论(0)
  • 2020-12-19 02:40

    Could not find any information that verifies this but I would use integers without a unit (if not percentage) in HTML and use "px" in CSS, except for zero values where it´s more correct to leave out the unit.

    http://www.w3.org/TR/CSS2/visudet.html#the-width-property

    0 讨论(0)
  • 2020-12-19 02:42

    As far as I know, you do not add the px label to width/height attribute values on the img tag itself, and I believe (though could be wrong) it's because pixels are used regardless. In CSS, however, one may use different units to specify width and height, therefore it is appropriate to add the label when using CSS.

    0 讨论(0)
  • 2020-12-19 02:51

    Use css to consider the the size of the image:

    CSS:

    .logo {
    width: 200px;
    height: 120px;
    }
    

    HTML:

    <img src="/logo.jpg" alt="logo" class="logo" />
    
    0 讨论(0)
提交回复
热议问题