如何在不重写的情况下中和CSS定义

sh3*_*211 3 css stylesheet twitter-bootstrap

有没有办法在不覆盖所有内容的情况下中和元素的CSS规则?

例如,我正在使用Twitter Bootstrap,它有许多预定义的CSS定义table.在某些地方,我不想要它们.

在某些table元素上,我想知道我是否可以这样做:

<table style="default"></table>
Run Code Online (Sandbox Code Playgroud)

Ben*_*ate 7

Bootstrap 只有一点 CSS <table>元素:

table {
  max-width: 100%;
  background-color: transparent;
  border-collapse: collapse;
  border-spacing: 0;
}
Run Code Online (Sandbox Code Playgroud)

要覆盖这些,你可以为你的表创建一个名为strapless的类:

table.strapless{
  max-width: 100%;
  background-color: transparent;
  border-collapse: separate;
  border-spacing: 2px;
  border-color: gray;
}
Run Code Online (Sandbox Code Playgroud)

table.strapless选择器将覆盖tablebootstrap使用的选择器,因为它更具体.

要使用css类,请将其包含在表的class属性中:

<table class="strapless">
Run Code Online (Sandbox Code Playgroud)