IE8非兼容模式,图像最大宽度和高度:auto
我有一个带有此标记的图像
<img src="wedding_00.jpg" width="900" height="600" />
,我正在使用 CSS 将其缩小到 600px 宽度,如下所示:
img {
max-width:600px;
height:auto;
}
任何人都可以解释为什么此方法在兼容模式下有效,但在标准模式下无效?有没有办法修改我的CSS,使其在标准模式下工作?
我意识到如果我去掉它就
width="900" height="600"
可以解决问题,但这不是我的选择。
I have an image with this markup
<img src="wedding_00.jpg" width="900" height="600" />
And I am using CSS to downsize it to 600px width, like so:
img {
max-width:600px;
height:auto;
}
Can anyone explain why this method works in Compatibility mode, but not in standard mode? Is there a way I can modify my CSS so that it will work in standard mode?
I realize that if I strip out the
width="900" height="600"
that it solves the problem, but that is not an option I have.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我不确定根本原因,但如果你添加
它就可以了。
I'm not sure of the root cause but if you add
then it works.
为 ie8 设置
width:inherit
set
width:inherit
for ie8哇,在那里节省了我很多时间!
我在位置:绝对位置的图像上遇到了类似的问题,其中宽度神奇地采用了最大宽度值。这很奇怪,因为当图像不在位置时它不会这样做:绝对。
在 IE8 中运行得很好!
Wow, saved me a lot of time there!
i had a similar problem with an image in position: absolute where width was magically taking max-width value. Its weird because it doesn't do that when the image wasn't in position: absolute.
works great in IE8!
哇,IE 看起来总是很痛苦。虽然有一个公认的答案,但我发现它并没有解决我的问题。
经过多次搜索,我发现修复它的方法是从相关图像中删除高度和宽度属性。可以在这里找到解释:缩放图像IE8 with CSS max-width
代码如下:
CSS:
SCRIPT
现在我倾向于尽可能多地使用 jQuery,为了解决这个问题我使用了一个一些针对 IE8 的不同功能让我的生活更轻松。我还发现该解决方案几乎有效,但不完全有效。我反复尝试,直到能够达到我想要的结果。我的解决方案如下:
JQUERY:
我使用它来定位特定的图像加载函数,但它也可以添加到任何文档就绪或窗口加载函数中。
Wow, what a pain IE always seems to be. Although there is an accepted answer, I found that it did not solve my problem.
After much search I found that the way to fix it is to remove the height and width attributes from the images in question. An explanation can be found here: Scaling Images in IE8 with CSS max-width
The code is as follows:
CSS:
SCRIPT
Now I tend to use jQuery as much as possible, to solve this I used a few different functions to target IE8 and make my life easier. I also found that the solution almost worked, but not quite. I toyed around with it until I was able to achieve the results I was looking for. My solution is as follows:
JQUERY:
I use this to target a specific image load function, but it could be added to any document ready or window load function as well.
我对这个问题的解决方案是:
My solution for this issue was:
当直接包装器 (div) 具有宽度时,图像的最大宽度在 IE8 上工作正常。
示例:
本例中的图像为 700px;
网页宽度为 900px;
如果您设置样式:
.wrapper1 { 宽度:50%;浮动:向左; }
// 该列的宽度最大为 450px;图像仍然是 700px,导致布局被破坏。
解决方案:
.wrapper1 { 宽度:50%;浮动:向左; }
// 此列的宽度最大为 450px;.wrapper2 { 宽度 100%;浮动:向左; }
// 如果有边框或填充,宽度会变小 100%当调整窗口大小时,图像将适合列(图像 = 450px),图像将根据wrapper2的宽度而变小。
问候,
江天
max-width of images just work fine on IE8 when it's directly wrapper (div) has width.
Example:
The image in this example is 700px;
The web's width is 900px;
<div class="wrapper1"><div class="wrapper2"><img style="max-width: 100%;" src="abc.jpg" alt="Abc" /></div></div>
if you style:
.wrapper1 { width: 50%; float: left; }
// this column's width is 450px max;The image still 700px and make the layout broken.
Solution:
.wrapper1 { width: 50%; float: left; }
// this column's width is 450px max;.wrapper2 { width 100%; float: left; }
// if it has border or padding, width will smaller 100%The the image will fit the column (image = 450px) when resize window smaller, image will smaller based on wrapper2's width.
Regards,
Cuong Sky