简体   繁体   English

如何在图像类的CSS中设置宽度和高度

[英]how to set width and height in css in image class

I am trying to set the width and height of my img picture in CSS but it doesn't work in my CSS. 我试图在CSS中设置img图片的宽度和高度,但在CSS中不起作用。 The only way that I could do this in my img tag in my other file. 我可以在其他文件的img标记中执行此操作的唯一方法。 I have done the following but can't get it to work: 我已完成以下操作,但无法正常工作:

img.whiteboard1 {
    width: 10em;
    height: 10em;
}

Try removing the word img, as shown below. 尝试删除单词img,如下所示。

.whiteboard1 {
width: 10em;
height: 10em;

} }

you need to know that <img> is an inline element. 您需要知道<img>是一个内联元素。 Inline element can not use the height and width properties. 内联元素不能使用heightwidth属性。 If you really want to set the height and width to <img> , set the display: inline-block to the <img> 如果您确实要将heightwidth设置为<img> ,则将display: inline-block设置为<img>

img.whiteboard1 {
    display: inline-block;
    width: 10em;
    height: 10em;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM