The issue at hand
An issue has been identified where the code functions as intended in Chrome, Opera, and IE but fails to work in Firefox:
fieldset>legend {
display: table;
float: none;
margin: 0 auto;
}
<fieldset>
<legend>Legend</legend>
</fieldset>
Outcome in Chrome
Outcome in Firefox
Potential Fixes Alternative Solutions
Various suggestions have been put forward, however, none have provided a satisfactory resolution:
/* intended styling */
fieldset>legend {
display: table;
float: none;
margin: 0 auto;
}
<fieldset.absolute-fix {
position: relative;
}
fieldset.absolute-fix>legend {
position: absolute;
left: 50%;
}
<fieldset.margin-fix>legend {
margin-left: 50%;
margin-right: 50%;
width: auto;
transform: translate(-50%, 0)
}
<fieldset.width-fix>legend {
width: 100%;
text-align: center;
}
<fieldset class="absolute-fix">
<legend>Fix with absolute</legend>
<p>Not centered and inconsistent styling</p>
<a href="http://stackoverflow.com/a/4006871/1185053">Source</a>
</fieldset>
<fieldset class="attribute-fix">
<legend align="center">Fix with attribute</legend>
<p>Requires use of deprecated HTML and strongly ties presentation to content.</p>
<a href="http://stackoverflow.com/a/19969606/1185053">Source</a>
</fieldset>
<fieldset class="margin-fix">
<legend>Fix with margin</legend>
<p>This is unsatisfactory because there is a misaligned gap in the border and long legends go over several lines.</p>
</fieldset>
<fieldset class="width-fix">
<legend>Fix with width</legend>
<p>This is unsatisfactory because there is a significant gap in the border.</p>
</fieldset>
Inquiry
Is there a method to consistently center legend
in Firefox while preserving styling for other browsers?