Reputation: 2085
I'm getting different results on my legend centering across browsers:
Should be like this:
But instead I get different margins on other browsers:
HTML
<div class="teaser-header">
<fieldset class="teaser-fieldset">
<legend class="teaser-legend">We are a very passionate team</legend>
<h1>Who we are</h1>
</fieldset>
</div>
CSS
.teaser-header {
padding-top: 70px;
}
.teaser-fieldset {
border: 1px solid white;
color: white;
text-align: center;
width: 400px;
margin: auto;
}
.teaser-fieldset h1 {
color: white;
text-align: center;
margin: 0;
padding-bottom: 20px;
font-family: "Montserrat";
}
.teaser-legend {
padding: 0 10px;
width: 80%;
margin-left: auto;
margin-right: auto;
color: white;
font-size: 1em;
text-transform: uppercase;
margin-bottom: 0;
}
Any ideas? Thanks!
Upvotes: 3
Views: 261
Reputation: 89790
Setting the margin-left
and margin-right
explicitly as 10% seems to fix the centering issue. The 10% value is nothing but half of (100% - width
).
.teaser-header {
padding-top: 70px;
}
.teaser-fieldset {
border: 1px solid white;
color: white;
text-align: center;
width: 400px;
margin: auto;
}
.teaser-fieldset h1 {
color: white;
text-align: center;
margin: 0;
padding-bottom: 20px;
font-family: "Montserrat";
}
.teaser-legend {
/* padding: 0 10px; remove this */
width: 80%;
margin-left: 10%; /* change this */
margin-right: 10%; /* change this */
color: white;
font-size: 1em;
text-transform: uppercase;
margin-bottom: 0;
text-align: center; /* add this */
}
body {
background: black;
}
<div class="teaser-header">
<fieldset class="teaser-fieldset">
<legend class="teaser-legend">We are a very passionate team</legend>
<h1>Who we are</h1>
</fieldset>
</div>
Upvotes: 3