覆盖并重置 CSS 样式:自动或无不起作用
我想覆盖为所有表定义的以下 CSS 样式:
table {
font-size: 12px;
width: 100%;
min-width: 400px;
display:inline-table;
}
我有一个特定的表,其类名为 'other'
。
最后表格装饰应该如下所示:
table.other {
font-size: 12px;
}
所以我需要删除 3 个属性:width
、min-width
和 display
我尝试使用 重置none
或 auto
,但没有帮助,我的意思是这些情况:
table.other {
width: auto;
min-width: auto;
display:auto;
}
table.other {
width: none;
min-width: none;
display:none;
}
I would like to override following CSS styling defined for all tables:
table {
font-size: 12px;
width: 100%;
min-width: 400px;
display:inline-table;
}
I have specific table with class called 'other'
.
Finally table decoration should looks like:
table.other {
font-size: 12px;
}
so i need remove 3 properties: width
,min-width
and display
I tried to reset with none
or auto
, but didn't help, I mean these cases:
table.other {
width: auto;
min-width: auto;
display:auto;
}
table.other {
width: none;
min-width: none;
display:none;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
我相信第一组属性不起作用的原因是因为
display
,因此应忽略该属性。在这种情况下,inline-table
仍然有效,并且由于width
不适用于inline
元素,因此该属性集将不起作用任何事物。第二组属性将简单地隐藏表格,因为这就是
display: none
的用途。尝试将其重置为
table
:编辑:
min-width
默认为0
,而不是auto
I believe the reason why the first set of properties will not work is because there is no
auto
value fordisplay
, so that property should be ignored. In that case,inline-table
will still take effect, and aswidth
do not apply toinline
elements, that set of properties will not do anything.The second set of properties will simply hide the table, as that's what
display: none
is for.Try resetting it to
table
instead:Edit:
min-width
defaults to0
, notauto
“none”不会做你认为它会做的事情。为了“清除”CSS 属性,您必须将其设置回 CSS 标准定义的默认值。因此,您应该在您最喜欢的参考中查找默认值。
"none" does not do what you assume it does. In order to "clear" a CSS property, you must set it back to its default, which is defined by the CSS standard. Thus you should look up the defaults in your favorite reference.
试试这个。它会起作用的。
Try this. It will work.
表的默认
display
属性为display:table;
。唯一有用的值是inline-table
。所有其他display
值对于表格元素均无效。没有
auto
选项可以将其重置为默认值,但如果您使用的是 Javascript,则可以将其设置为空字符串,这样就可以解决问题。width:auto;
有效,但不是默认值。表格的默认宽度为100%
,而width:auto;
将使元素仅占用所需的宽度。不允许使用
min-width:auto;
。如果设置min-width
,它必须有一个值,但将其设置为零可能与将其重置为默认值一样好。The default
display
property for a table isdisplay:table;
. The only other useful value isinline-table
. All otherdisplay
values are invalid for table elements.There isn't an
auto
option to reset it to default, although if you're working in Javascript, you can set it to an empty string, which will do the trick.width:auto;
is valid, but isn't the default. The default width for a table is100%
, whereaswidth:auto;
will make the element only take up as much width as it needs to.min-width:auto;
isn't allowed. If you setmin-width
, it must have a value, but setting it to zero is probably as good as resetting it to default.好吧,
display: none;
根本不会显示表格,请尝试display: inline-block;
并将宽度和最小宽度声明保留为“auto”。Well,
display: none;
will not display the table at all, trydisplay: inline-block;
with the width and min-width declarations remaining 'auto'.我发现恢复最小宽度设置的最佳方法是:
未设置在规范中,但某些浏览器(IE 10)不尊重它,因此 0 在大多数中是一个很好的后备案例。
最小宽度:0;
The best way that I've found to revert a min-width setting is:
unset is in the spec, but some browsers (IE 10) do not respect it, so 0 is a good fallback in most cases.
min-width: 0;
我最终使用 Javascript 来完善一切。
我的JS小提琴: https://jsfiddle.net/QEpJH/612/
HTML:
CSS:
JS:
I ended up using Javascript to perfect everything.
My JS fiddle: https://jsfiddle.net/QEpJH/612/
HTML:
CSS:
JS:
我尝试过:
为我工作
I have tried:
Worked for me