"Unrendered margin-top is on fieldset's legend"
P粉659516906
P粉659516906 2024-04-04 19:40:04
0
2
3698

I have some HTML code equivalent to:

<div style="border: 1px solid black">
  <fieldset style="margin: 0">
    <legend style="margin-top: 20px;">testing....</legend>
  </fieldset>
</div>

My question is why the margin-top on the legend is not rendered? I want to solve this problem using only CSS. Thanks!

P粉659516906
P粉659516906

reply all(2)
P粉521013123

If you really want to do this, then set legend { float: left; }:

legend {
  float: left;
}
<div style="border: 1px solid black">
  <fieldset style="margin: 0">
    <legend style="margin-top: 20px;">testing....</legend>
  </fieldset>
</div>
P粉593118425

Try using padding instead. This will work.

The reason why margin doesn't work is because the distance between the border and the text content is called padding instead of margin.

<div style="border: 1px solid black">
  <fieldset style="margin: 0">
    <legend style="padding-top: 20px;">testing....</legend>
  </fieldset>
</div>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template