Skip to content Skip to sidebar Skip to footer

How To Remove Space Below Fieldset Legend

I am using a table inside fieldset and there is a gap below legend, I wand to remove it. I tried using padding:0px and margin:0px on both fieldset and legend inline style. But none

Solution 1:

According to Eric Meyer's reset, margin:0; and padding:0; on both fieldset and legend should do the job.

Testing your code in a fiddle it actually worked, so a couple of other things that may cause this issue are:

  1. Padding / margin set on the table / td
  2. Line-height of label / td

Solution 2:

Default rendering may include padding intended to make the document appearance legible. The defaults vary by browser, but they may include vertical padding on fieldset and legend, and they almost certainly include vertical padding on td elements. To remove such padding, you can set:

legend { 
  padding-top: 0;
  padding-bottom: 0;
}
fieldset, td { 
  padding-top: 0;
}

But there’s also spacing between table cells by default, and this means that there is some spacing around a cell even in a single-cell table. The cross-browser way to remove that is:

table {
  border-collapse: collapse;
}

Adding this removes the spacing between the legend and the cell content (you can see this by setting background colors on the legend and label elements) on IE and Chrome. On Firefox, a one-pixel gap seems to remain, with no obvious explanation.

Solution 3:

To remove the space below label use margin-top: -ve px;

Just like:

<fieldset> <legend><b>Options</b></legend> <table style="margin-top:-13px;"> <tr> <td colspan="1"><label>Passengers:&nbsp; </label></td></tr></table> </fieldset>

Solution 4:

Browser formatting of fieldset and legend varies widely between browsers but in any case is a mess.

If you have any whitespace between your opening fieldset tag and the first tag firefox will add BREAKS. Same goes for legends.

The easiest way to get around itis to remove all whitespace between your tags.

Solution 5:

I was just fighting with this too, to get the same behaviour between browsers when using absolute positioning inside a fieldset.

What I found would happen when adding a legend to a fieldset was that Chrome and IE would move the top border of the fieldset down to the middle of the text, but the contained elements were still positioned relative to the original top of the fieldset. But Firefox would also move the top of the contained elements to below the legend. FF would also allow space above and below the legend text itself.

I finally was able to overcome it by adding this CSS:

legend {
   line-height: 0;
}

The legend was then added without moving the top border and the positioning was the same in Chrome, IE and FF.

Post a Comment for "How To Remove Space Below Fieldset Legend"