Dynamic class to element with Less

2019-08-06 18:51发布

问题:

I am using bootstrap.less and i want to add class="table table-striped table-hover" to all tables. Is it possible to achieve this?

I want to add something like:

table {
   //Add class here
}

回答1:

If I understand you correctly, I believe you're looking for:

table {
  .table;
  .table-striped;
  .table-hover;

  /* Any other default table styles */
}

While you can't add class="table table-striped table-hover" to each element (that's more in the JS-realm), you can get the same effect by using the other classes as mixins added to the default table element's styles. See the LESS documentation for more examples.