CSS 为在 IE 中不起作用的元素使用初始宽度
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20823105/
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
use initial width for element not working in IE
提问by Rikard
I have a graph plugin that inserts canvas and a legend <table>
to its container. In this plugin the table
has no width
defined and in my CSS there is a width for tables inside that container were my plugin gets inserted.
我有一个图形插件,可将画布和图例插入<table>
其容器。在这个插件table
中没有width
定义,并且在我的 CSS 中,当我的插件被插入时,该容器内的表格有一个宽度。
So, the new div is inheriting table{ width: 100%}
from the CSS and rendering wrong.
因此,新的 div 是table{ width: 100%}
从 CSS继承的,并且呈现错误。
I tried to use width: initial;
, looks good on Chrome but IE doesn't like itcheck browser compatibility
我尝试使用width: initial;
,在 Chrome 上看起来不错,但IE 不喜欢它检查浏览器兼容性
I admit changing/forcing a inline CSS in the script/plugin since it has to work in any enviroment.
我承认更改/强制脚本/插件中的内联 CSS,因为它必须在任何环境中工作。
What is the best solution here?
这里最好的解决方案是什么?
回答by Mark Rhodes
Like you said, generally width: auto
will have a similar effect. Having the rules:
像你说的,一般width: auto
都会有类似的效果。有规则:
.my-selector {
width: auto;
width: initial;
}
Should cause it to use initial
if it's supported and auto
otherwise.
如果initial
受支持,则应使其使用,auto
否则应使用。
回答by Rikard
Using width: auto;
inline, inside the script solves the problem on Chrome, FIrefox and IE 11. Just not sure if there is a better way.
使用width: auto;
内联,在脚本内部解决了 Chrome、Firefox 和 IE 11 上的问题。只是不确定是否有更好的方法。