Html IE8 中的 CSS 最大宽度
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17392265/
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
CSS Max-Width in IE8
提问by Kevin Meredith
For my input, which can either have classname="half"
or "half.not-placeholder-value"
, Firebug shows both inputs to have a set, fixed width of 25em
.
对于我的输入,它可以有classname="half"
或"half.not-placeholder-value"
,Firebug 显示两个输入都有固定的25em
.
input.half, input.half.not-placeholder-value {
max-width: 25em;
}
Yet, according to Developer Tools, IE8 doesn't seem to use this particular max-width
attribute. I say "doesn't seem to use" since Firefox's behavior differs with IE8 with respect to this attribute.
然而,根据开发者工具,IE8 似乎并没有使用这个特定的max-width
属性。我说“似乎没有使用”,因为 Firefox 的行为与 IE8 就该属性而言不同。
But the MDN docssay that IE7 supports max-width
. Am I missing something?
但是 MDN文档说 IE7 支持max-width
. 我错过了什么吗?
回答by Raphael Rafatpanah
This is not really an IE8 issue since IE8 doessupport the max-width attribute but only when given a defined width first.
这实际上并不是 IE8 的问题,因为 IE8确实支持 max-width 属性,但前提是首先给出定义的宽度。
input.half, input.half.not-placeholder-value {
width: 100%;
max-width: 25em;
}
回答by Jason Lydon
Use IE8 css with width
? First part targets IE, second part undoes it for IE9+.
将 IE8 css 与width
? 第一部分针对 IE,第二部分针对 IE9+ 撤消它。
input.half, input.half.not-placeholder-value {
max-width: 25em;
width:25em; /* IE 8 */
}
:root input.half, input.half.not-placeholder-value {
width:inherit; /* IE 9+ */
}