How can I override Bootstrap CSS styles?

I need to modify bootstrap.css to fit my website. I feel it’s better to create a separate custom.css file instead of modifying bootstrap.css directly, one reason being that should bootstrap.css get an update, I’ll suffer trying to re-include all my modifications. I’ll sacrifice some load time for these styles, but it’s negligible for the few styles I’m overriding.

Hw do I override bootstrap.css so that I remove the style of an anchor/class? For example, if I want to remove all the styling rules for legend:

legend {
  display: block;
  width: 100%;
  padding: 0;
  margin-bottom: 20px;
  font-size: 21px;
  line-height: inherit;
  color: #333333;
  border: 0;
  border-bottom: 1px solid #e5e5e5;
}

I can just delete all that in bootstrap.css, but if my understanding about best practices on overriding CSS is correct, what should I do instead?

To be clear, I want to remove all those styles of legend and use parent’s CSS values. So combining Pranav’s answer, will I be doing the following?

legend {
  display: inherit !important;
  width: inherit !important;
  padding: inherit !important;
  margin-bottom: inherit !important;
  font-size: inherit !important;
  line-height: inherit !important;
  color: inherit !important;
  border: inherit !important;
  border-bottom: inherit !important;
}

(I was hoping there’s a way to do something like the following:)

legend {
  clear: all;
}

13 Answers
13

Leave a Comment