Html CSS 将表重置为默认等效项
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13076227/
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
CSS Reset table to default equivalent
提问by chris
I am working with a pre-made bought template, where the author of said template wired things together in such a way where its next to impossible sometimes to get something the way you want, in this case I have a table I am trying to put in to a section of the template, that I don't need or want styled the way they have the template do it. However because of how they did it I can't just go altering the CSS to do something else. I have tried classing the table as something else and styling it the way I want, but there's something that always manages to get snagged somewhere and the author's style persists on one piece or another of the table. So with that I came up with the idea, why not make a reset like class specific to tables that I can call this class in first on the element, then the class I want it to be styled under e.g.:
我正在使用一个预制的购买模板,其中所述模板的作者以这样的方式将事物连接在一起,有时几乎不可能以您想要的方式获得某些东西,在这种情况下,我有一张桌子,我正在尝试放置在模板的一部分中,我不需要或不想按照他们使用模板的方式进行样式设置。然而,由于他们是如何做到的,我不能只是改变 CSS 来做其他事情。我曾尝试将桌子归类为其他东西,并按照我想要的方式对其进行样式设置,但总有一些东西会在某处卡住,而作者的风格仍然存在于桌子的一张或另一张上。因此,我想出了这个想法,为什么不重新设置特定于表的类,我可以首先在元素上调用这个类,然后是我希望它的样式如下的类,例如:
class="reset_table mynew_style"
class="reset_table mynew_style"
So I am trying to come up with a means of doing it, but am getting stuck.
所以我试图想出一种方法来做到这一点,但我被卡住了。
.reset_table,
.reset_table table tr,
.reset_table tr td,
.reset_table table tbody,
.reset_table table thead,
.reset_table table tfoot,
.reset_table table tr th,
.reset_table table tfoot tr tf
{
margin:0;
padding:0;
background:none;
border:none;
border-collapse:collapse;
border-spacing:0;
background-image:none;
}
Now this seems to work almost completely, there's still some things persisting. So I'm hoping someone here can help me come up with a better variation of this. So all bases are covered in the sense of trying to reset a table back to normal default style.
现在这似乎几乎完全有效,但仍有一些事情仍然存在。所以我希望这里有人可以帮助我想出一个更好的变体。因此,从尝试将表格重置为正常默认样式的意义上讲,所有基础都已涵盖。
回答by bit-less
It's an old thread, but in case this is helps someone else:
这是一个旧线程,但如果这对其他人有帮助:
.clear-user-agent-styles table,
.clear-user-agent-styles thead,
.clear-user-agent-styles tbody,
.clear-user-agent-styles tfoot,
.clear-user-agent-styles tr,
.clear-user-agent-styles th,
.clear-user-agent-styles td {
display: block;
width: auto;
height: auto;
margin: 0;
padding: 0;
border: none;
border-collapse: inherit;
border-spacing: 0;
border-color: inherit;
vertical-align: inherit;
text-align: left;
font-weight: inherit;
-webkit-border-horizontal-spacing: 0;
-webkit-border-vertical-spacing: 0;
}
th, td {
display: inline;
}
If it's still not overriding other dev styles, make sure you have this code after theirs, or be more specific by including the parent class, or even ID if you need to. Try, to avoid appending !importantto the end of each property's value, but that would mostly likely trump what was coded previously.
如果它仍然没有覆盖其他开发样式,请确保在它们之后有此代码,或者通过包含父类或 ID(如果需要)来更具体。尝试避免将!important附加到每个属性值的末尾,但这很可能会胜过之前编码的内容。