Html 图像高度和宽度不起作用?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10270075/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Image height and width not working?
提问by Mark R
On this post I have set the image height and width and it's clearly seen in the HTML..
在这篇文章中,我设置了图像的高度和宽度,并且在 HTML 中可以清楚地看到..
[url removed]
[网址已删除]
But the browser or Wordpress is causing the image to stay same size.
但是浏览器或 Wordpress 导致图像大小保持不变。
I want it to be smaller?
我想让它更小?
回答by Mageek
You must write
你必须写
<img src="theSource" style="width:30px;height:30px;" />
Inline styling will always take precedence over CSS styling. The width and height attributesare being overridden by your stylesheet, so you need to switch to this format.
内联样式始终优先于 CSS 样式。width 和 height属性被您的样式表覆盖,因此您需要切换到这种格式。
回答by Andres Ilich
You have a class on your CSS that is overwriting your width and height, the class reads as such:
您的 CSS 上有一个类会覆盖您的宽度和高度,该类内容如下:
.postItem img {
height: auto;
width: 450px;
}
Remove that and your width/height properties on the img
tag should work.
删除它,img
标签上的宽度/高度属性应该可以工作。
回答by maiorano84
http://www.markrafferty.com/wp-content/w3tc/min/7415c412.e68ae1.css
http://www.markrafferty.com/wp-content/w3tc/min/7415c412.e68ae1.css
Line 11:
第 11 行:
.postItem img {
height: auto;
width: 450px;
}
You can either edit your CSS, or you can listen to Mageek and use INLINE STYLINGto override the CSS styling that's happening:
你可以编辑你的 CSS,或者你可以听 Mageek 并使用INLINE STYLING来覆盖正在发生的 CSS 样式:
<img src="theSource" style="width:30px;" />
Avoid setting both width and height, as the image itself might not be scaled proportionally. But you can set the dimensions to whatever you want, as per Mageek's example.
避免同时设置宽度和高度,因为图像本身可能不会按比例缩放。但是您可以根据 Mageek 的示例将尺寸设置为任何您想要的尺寸。