简体   繁体   English

如何删除fieldset图例下面的空格

[英]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. 我在fieldset使用了一个表,并且在图例下面有一个fieldset ,我想要删除它。 I tried using padding:0px and margin:0px on both fieldset and legend inline style. 我尝试在fieldset和legend inline样式上使用padding:0pxmargin:0px But none worked. 但都没有效果。 Please help me with some suggestions. 请帮我一些建议。

Thanks! 谢谢!

Edit: 编辑:

The code is very huge since I am using select menu. 由于我使用的是选择菜单,因此代码非常庞大。 But here is the overview of the code. 但这里是代码的概述。

<fieldset>
          <legend><b>Options</b></legend>
          <table>
            <tr>
              <td colspan="1"><label>Passengers:&nbsp; </label></td></tr></table>    
</fieldset>

margin and padding is working for fieldset but it is doing nothing for legend. margin和padding适用于fieldset,但它对于图例没有任何作用。 Is there any way to remove the gap produced by legend? 有没有办法消除传奇产生的差距?

According to Eric Meyer's reset , margin:0; 根据Eric Meyer的重置margin:0; and padding:0; padding:0; on both fieldset and legend should do the job. 在fieldset和legend上都应该完成这项工作。

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 填充/边距设置在表/ td上
  2. Line-height of label / td 标签的行高/ td

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. 默认值因浏览器而异,但它们可能包括fieldsetlegend上的垂直填充,并且它们几乎肯定包括td元素上的垂直填充。 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. 添加此选项可删除图例和单元格内容之间的间距(您可以通过在legendlabel元素上设置背景颜色来查看)在IE和Chrome上。 On Firefox, a one-pixel gap seems to remain, with no obvious explanation. 在Firefox上,一个像素的差距似乎仍然存在,没有明显的解释。

To remove the space below label use margin-top: -ve px; 要删除标签下面的空格,请使用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>

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. 如果您的开放字段集标记和第一个标记之间有任何空格,则Firefox将添加BREAKS。 Same goes for legends. 同样适用于传说。

The easiest way to get around itis to remove all whitespace between your tags. 绕过它的最简单方法是删除标记之间的所有空格。

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. 我发现在向fieldset添加legend时会发生Chrome和IE会将字段集的顶部边框向下移动到文本的中间位置,但所包含的元素仍然相对于字段集的原始顶部定位。 But Firefox would also move the top of the contained elements to below the legend. 但Firefox也会将所包含元素的顶部移动到图例下方。 FF would also allow space above and below the legend text itself. FF还允许在图例文本本身的上方和下方留出空间。

I finally was able to overcome it by adding this CSS: 我终于能够通过添加这个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. 然后添加图例而不移动顶部边框,Chrome,IE和FF中的定位相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM