2024-02-07 08:00:06

如何覆盖!重要?

我已经创建了一个自定义样式表,它覆盖了我的Wordpress模板的原始CSS。然而,在我的日历页面上,原始CSS有每个表单元格的高度设置!重要声明:

td {height: 100px !important}

有什么办法能让我无视它吗?


当前回答

这也有帮助

td[style] {height: 50px !important;}

这将覆盖任何内联样式

其他回答

使用JavaScript重写

$('.mytable td').attr('style', 'display: none !important');

为我工作。

在任何情况下,您都可以使用max-height覆盖height。

样式名称的每个部分都有权重,因此与该样式相关的元素越多,它就越重要。例如

#P1 .Page {height:100px;}

比:

.Page {height:100px;}

所以当使用important时,理想情况下,这个应该只在真正需要的时候使用。因此,要重写声明,使样式更具体,但也要使用重写。见下文:

td {width:100px !important;}
table tr td .override {width:150px !important;}

你可以在选择器中使用更高的特异性。

td {height: 100px !important}
/* higher precedence */
table td {height: 200px !important}

我在这里写了一篇关于如何重写CSS的详细文章。

这也有帮助

td[style] {height: 50px !important;}

这将覆盖任何内联样式