Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Override Bootstrap 5 fieldset style

Back in previous versions of Bootstrap (and also with vanilla CSS), the following HTML:

<fieldset>
  <legend>Test</legend>
    Welcome!
</fieldset>

Outputs a fieldset with a border, where the legend goes over it:

Fieldset with legend over its border

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Nevertheless, when the same HTML is used alongside Bootstrap 5, the output looks like this:

Fieldset in Bootstrap 5

How can I override bootstrap CSS, so the fieldset has its border visible again with its legend over it?

>Solution :

Any css can be reset to its default by using revert:

fieldset, legend {
   all: revert;
}
.reset {
    all: revert;
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet"/>

<fieldset>
    <legend>Legend</legend>
</fieldset>

<fieldset class="reset">
    <legend class="reset">Reset legend</legend>
</fieldset>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading