最大高度和宽度会增加图像大小

时间:2015-09-01 07:40:11

标签: html css

我有一个图片标签。我试图将max height和width属性设置为600 px。现在,如果图像尺寸小于它,则会增加图像尺寸。我只想在图像超过600像素时才有最大高度和宽度。

<img src="8.jpg" style="max-height: 600px;max-width:600px;/">

4 个答案:

答案 0 :(得分:1)

它运作正常,你可以用错误的例子做个小提琴吗?

<img src="http://www.waltereul.de/walter-eul-pictures/walter-eul_100x100_10.jpg" style="max-height: 200px;max-width:200px;/">
<img src="http://www.zenimax.com/jpn/fallout3/images/avators/100x100falloutav-vb.gif" style="max-height: 200px;max-width:200px;/">

example

答案 1 :(得分:0)

对我来说,看起来你的img-tag受到另一个影响图像宽度/高度的css规则的影响。我建议您使用浏览器的开发者工具来检查哪些css规则会影响您的img-tags(如果需要,可以使用教程:https://developer.mozilla.org/en-US/Learn/Discover_browser_developer_tools)。

同样在上面的代码示例中,斜杠应该在style-attribute之外,如下所示:

<img src="8.jpg" style="max-height: 600px;max-width:600px;" />

答案 2 :(得分:0)

max-width目的是将大分辨率图像限制为指定大小。 所以,基本上max-width itsef不能强制放大较小的图像。 我敢打赌,这些图片会受到其他CSS的影响。如上所述:

“max-width属性用于设置元素的最大宽度。

这可以防止width属性的值大于max-width。“ - http://www.w3schools.com/cssref/pr_dim_max-width.asp

答案 3 :(得分:0)

请尝试这一个:

一种方法

<img src="8.jpg" style="max-height: 200px;max-width:200px;/">

另一种方法是这样的:

<img src="8.jpg" />

Css代码:

img{
    width:100%;
    max-width:600px;
}