停止site.css覆盖表样式

Stop site.css overriding table style

本文关键字:样式 覆盖 css site 停止      更新时间:2023-09-26

在我的ASP.NET MVC应用程序中,site.css文件中的表样式定义为:

table {
    border-collapse: collapse;
    border-spacing: 0;
    margin-top: 1em;
    border: 0 none;
}

当我创建一个表并在HTML中显式设置border属性时,css中的这种样式将覆盖border属性。结果是我无法在表中看到边框。这是我的表格变量:

tableT = '<table border="1" style="float:center" id="itemList"><thead><tr><td></td><td>Total</td><td>Completed</td><td>Inprogress</td><td>Pending</td></tr></thead><tbody></tbody></table>',

我想要一个带边框的表,我不想像在其他地方一样更改site.css

您可以尝试使用带有!important规则的内联样式:

<table border="1" style="float:center; border: 1px solid !important;" id="itemList">

然而,这是一个相当混乱的破解方法,Germain从评论中给出的答案将是一个更优雅的解决方案——这取决于你是否能够/倾向于编辑你的CSS文件。