CSS IE 不支持 height=auto 图像,我应该使用什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8673356/
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
IE doesn't support height=auto for images, what should I use?
提问by Travis J
I have some images with height=auto because sometimes they are different heights whereas they are always the same width. It works in every browser but I.E., is there something similar I can use?
我有一些高度=自动的图像,因为有时它们的高度不同,而它们的宽度始终相同。它适用于除 IE 之外的所有浏览器,我可以使用类似的东西吗?
采纳答案by Travis J
The solution was to add the typical IE fix :(
解决方案是添加典型的 IE 修复:(
css:
css:
height:auto !important;
回答by WebDude0482
I found that adding min-height:1px
solves the issue. Not sure why, but, worked for me.
我发现添加min-height:1px
解决了这个问题。不知道为什么,但是,对我有用。
回答by Dion
Just leave
走吧
height=auto
out. If it's not given it's "auto" by default...
出去。如果没有给出它默认为“自动”......
回答by timc
i've tried all the solutions posted, and the only one that works is
我已经尝试了所有发布的解决方案,唯一有效的是
height=100%
回答by Rod
Use height: auto together with width: auto and it is going to work in IE. If you specify only one of them, IE gets upset.
将 height: auto 与 width: auto 一起使用,它将在 IE 中工作。如果您只指定其中之一,IE 会感到不安。
height: auto;
width: auto;
回答by Simon
You can do width="100%"
and max-width="100px"
or whatever width you want and then simply height="auto"
. This worked for me.
你可以做width="100%"
和max-width="100px"
或任何你想要的宽度,然后简单地height="auto"
. 这对我有用。
BTW you may need min-width
width your wanted width too if your parent element doesn't have the width that you want for your image.
顺便说一句,min-width
如果您的父元素没有您想要的图像宽度,您可能也需要宽度。
回答by user3548525
For Edge browser you can use max-height, which will also work for other browsers
对于 Edge 浏览器,您可以使用 max-height,这也适用于其他浏览器
max-height: 100%;
回答by Maciej Wira
I had the same problem and fixes with min-height and !important didn't work for me. My img was in a flex container. I then tried putting the img inside another, wrapping div and then height:auto worked.
我遇到了同样的问题,并修复了 min-height 和 !important 对我不起作用。我的 img 在一个 flex 容器中。然后我尝试将 img 放在另一个里面,包装 div 然后 height:auto 工作。
回答by Andy
There is also an IE issue when using images with height=auto
within flex containers.
height=auto
在 flex 容器中使用图像时也存在 IE 问题。
For me personally, the issue was caused due to the image being placed within nested flex containers. I was able to remove the parent flex container and the issue was resolved for me.
就我个人而言,这个问题是由于图像被放置在嵌套的 flex 容器中引起的。我能够删除父 flex 容器,问题已为我解决。
There are a few more work around solutions that people have mentioned in the page below: https://github.com/philipwalton/flexbugs/issues/75
人们在以下页面中提到的解决方案还有一些解决方案:https: //github.com/philipwalton/flexbugs/issues/75
回答by Alex Pierce
In "IE9 compatibility view - IE7 Standard Document mode" leaving off height=auto may not solve the problem. Try adding conditional CSS and in your special css file for IE ("ie.css") add a line that assigns the appropriate min-height to your affected class/element.
在“IE9 兼容性视图 - IE7 标准文档模式”中,去掉 height=auto 可能无法解决问题。尝试添加条件 CSS,并在 IE 的特殊 css 文件(“ie.css”)中添加一行,为受影响的类/元素分配适当的最小高度。
for example:
例如:
.IE7 .[css element] {min-height: xxxpx;}
.IE7 .[ css 元素] {min-height: xxxpx;}
Where xxx equals the necessary image height.
其中 xxx 等于必要的图像高度。