覆盖和重置CSS样式:自动或无don';行不通

覆盖和重置CSS样式:自动或无don';行不通,css,width,overriding,Css,Width,Overriding,我希望覆盖为所有表定义的以下CSS样式: table { font-size: 12px; width: 100%; min-width: 400px; display:inline-table; } 我有一个名为“其他”的类的特定表。 最后,桌面装饰应如下所示: table.other { font-size: 12px; } 所以我需要删除3个属性:width、minwidth和display 我试图用non

我希望覆盖为所有表定义的以下CSS样式:

table {
        font-size: 12px;
        width: 100%;
        min-width: 400px;
        display:inline-table;
    }
我有一个名为“其他”的类的特定表。
最后,桌面装饰应如下所示:

table.other {
    font-size: 12px;
}
所以我需要删除3个属性:
width
minwidth
display

我试图用
none
auto
重置,但没有帮助,我指的是以下情况:

table.other {
    width: auto;
    min-width: auto;
    display:auto;
}
table.other {
    width: none;
    min-width: none;
    display:none;
}

嗯,
显示:无根本不会显示表格,请尝试
显示:内联块的宽度和最小宽度声明保持为“自动”。

“无”不会执行您假定的操作。为了“清除”CSS属性,必须将其设置回CSS标准定义的默认值。因此,您应该在您最喜欢的引用中查找默认值

table.other {
    width: auto;
    min-width: 0;
    display:table;
}

我认为,第一组属性不起作用的原因是没有的
auto
值,因此应该忽略该属性。在这种情况下,
inline table
仍将生效,并且由于
width
不适用于
inline
元素,该属性集将不会起任何作用

第二组属性将简单地隐藏该表,因为这就是
display:none
的用途

尝试将其重置为
表格

table.other {
    width: auto;
    min-width: 0;
    display: table;
}

编辑:默认为
0
,而不是
auto

表的默认
display
属性是
display:table。唯一其他有用的值是
内联表
。所有其他
显示
值对于表元素无效

没有一个
auto
选项可以将其重置为默认值,尽管如果您使用Javascript,可以将其设置为空字符串,这将起到作用

宽度:自动有效,但不是默认值。表格的默认宽度为
100%
,而
width:auto
将使元素只占据所需的宽度

最小宽度:自动是不允许的。如果设置
minwidth
,它必须有一个值,但将其设置为零可能与将其重置为默认值一样好

Set min-width: inherit /* Reset the min-width */

试试这个。它会工作的。

我最终用Javascript完善了一切

我的小提琴:

HTML:

JS:

$(“.container”)。每个(函数(){
var divH=$(this).height()
var divW=$(this).width()
var imgH=$(this).children(“img”).height();
var imgW=$(this).children(“img”).width();
如果((imgW/imgH)<(divW/divH)){
$(此).addClass(“1”);
var newW=$(this).width();
var newH=(newW/imgW)*imgH;
$(此).children(“img”).width(newW);
$(此)。儿童(“img”)。身高(新高度);
}否则{
$(此).addClass(“2”);
var newH=$(this.height();
var newW=(newH/imgH)*imgW;
$(此).children(“img”).width(newW);
$(此)。儿童(“img”)。身高(新高度);
}
})

我发现恢复最小宽度设置的最佳方法是:

min-width: 0;
min-width: unset;
unset在规范中,但是一些浏览器(IE 10)不尊重它,所以在大多数情况下0是一个很好的回退。
最小宽度:0

奇怪的是,我在看firebug-最小宽度没有被auto@sergionni哦,是的,我忘了-
minwidth
有一个默认值
0
-我再次查看了firebug,还有一个问题,它们有嵌套的表,因此,重写应该应用于所有hierarchy@sergionni您可以通过将
table.other table
添加到用于重置属性的选择器
width:auto
,而我只想覆盖
width:100%
——谢谢您关于JS的有趣想法。看起来是我需要的。我会先试试CSS。这应该是一个公认的答案
min width:0
不会做同样的事情,但是如果父项有一个
min width
?你会得到它,而不是真正的违约。
.container {
    background-color:#000;
    width:100px;
    height:200px;

    display:flex;
    justify-content:center;
    align-items:center;
    overflow:hidden;

}
$(".container").each(function(){
    var divH = $(this).height()
    var divW = $(this).width()
    var imgH = $(this).children("img").height();
    var imgW = $(this).children("img").width();

    if ( (imgW/imgH) < (divW/divH)) { 
        $(this).addClass("1");
        var newW = $(this).width();
        var newH = (newW/imgW) * imgH;
        $(this).children("img").width(newW); 
        $(this).children("img").height(newH); 
    } else {
        $(this).addClass("2");
        var newH = $(this).height();
        var newW = (newH/imgH) * imgW;
        $(this).children("img").width(newW); 
        $(this).children("img").height(newH); 
    }
})
min-width: 0;
min-width: unset;