akantoword akantoword - 2 months ago 9x
CSS Question

Return default styling to legend element

My less file is set so that a legend that is a child of a fieldset has certain styles. I to make a legend.default that is a also a child of fieldset, but which will have its default styling. I don't want to list out every property and write in it's default styling. Is there a way to make this.legend.dafault not have any inherited styles or anything?


There is no way to actually revert a property to default, but you can use :not to define the styles only for the non-default legends.

fieldset legend:not(.default) {
  /* certain styles */

See :not(X) on CSS Tricks. Note that this works fine in all major browsers if you use a simple selector like in the example. Complex selectors cannot be used yet as the argument for :not(), since no major browser supports it at the time of writing.

Personally, I'd rather define styling for a specific class, and add that class to the legends that you do want to style, instead of using this negation-solution, but I'll leave that decision to you.