Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 834
Sergio Palmeiras Avatar asked Dec 21 '25 11:12

Sergio Palmeiras


2 Answers

Had the same issue and the following approach helped in my case. Refer to the following for further details.

https://github.com/twbs/bootstrap/issues/32548

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
</head>
<body>
    <div class="container">
        <fieldset class="border rounded-3 p-3">
            <legend class="float-none w-auto px-3" >Test</legend>
            Welcome!
        </fieldset>
    </div>
</body>
</html>
like image 194
kinath_ru Avatar answered Dec 23 '25 02:12

kinath_ru


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/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"/>

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

<fieldset class="reset">
    <legend class="reset">Reset legend</legend>
</fieldset>
like image 37
dantheman Avatar answered Dec 23 '25 04:12

dantheman