无法将“margin”添加到 Safari 和 Safari 中的“”元素Chrome(网络工具包)

发布于 2024-08-27 17:07:59 字数 865 浏览 5 评论 0原文

编辑:截至2012年6月11日,此错误终于得到修复! https://bugs.webkit.org/show_bug.cgi?id=35981# c1

我有一些非常简单的标记:

<form action="">
    <fieldset class="compact">                  
        <legend>Member Tools</legend>
        <label for="username">Username</label>
        <input name="username" id="username" type="text"/>
        <label for="password">Password</label>
        <input name="password" id="password" type="password" />
    </fieldset>
</form>

我试图在 legend 元素的底部添加一个小边距,这在 Firefox 2 和 3 以及 IE 5 中工作得很好- 8,但是在 Safari 和 Chrome 中添加 margin 没有任何作用。据我所知 legend 只是另一个块级元素,Webkit 添加 margin 应该没有问题,还是我不正确?

EDIT: As of 2012-06-11 this bug has been finally fixed! https://bugs.webkit.org/show_bug.cgi?id=35981#c1

I have some pretty straightforward markup:

<form action="">
    <fieldset class="compact">                  
        <legend>Member Tools</legend>
        <label for="username">Username</label>
        <input name="username" id="username" type="text"/>
        <label for="password">Password</label>
        <input name="password" id="password" type="password" />
    </fieldset>
</form>

I am attempting to add a small margin to the bottom of the legend element, this works just fine in Firefox 2 and 3 as well as IE 5-8, however in Safari and Chrome adding a margin does nothing. As far as I know legend is just another block level element and Webkit should have no issue adding a margin to it, or am I incorrect?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

扛刀软妹 2024-09-03 17:08:00

经过一番研究后,我找到了一种解决方法,我认为这是解决该问题的最不“hacky”的方法。使用令人讨厌的 webkit 定位黑客确实不是一个选择,但我发现 -webkit-margin-collapse: alone 属性似乎可以阻止元素上的边距折叠,正如它所描述的那样。

因此,在我的场景中,以下通过在字段集中第一个标签元素的顶部(图例正下方)添加边距来解决问题:

fieldset > label:first-of-type
{
-webkit-margin-top-collapse: separate;
margin-top: 3px;
}

并不完美,但总比没有好,其他浏览器应该正常折叠边距。

如果有人好奇,确实有人提交了有关此问题的错误报告 # 35981

https://bugs。 webkit.org/show_bug.cgi?id=35981

感谢大家的意见。

After a bit of research I found a work-around for this that I believe to be the least "hacky" method for solving it. Using the nasty webkit targeting hacks really weren't an option, but I found that the -webkit-margin-collapse: separate property seems to work in stopping the margins on the elements from collapsing just as it describes.

So in my scenario the following fixes the issue by adding a margin to the top of the first label element (right below the legend) in the fieldset:

fieldset > label:first-of-type
{
-webkit-margin-top-collapse: separate;
margin-top: 3px;
}

Not perfect, but better than nothing, other browsers should just collapse the margins normally.

If anyone is curious someone actually did file a bug report about this # 35981

https://bugs.webkit.org/show_bug.cgi?id=35981

Thanks for everyone's input.

哭了丶谁疼 2024-09-03 17:08:00

好吧,

确实不是“只是另一个块级元素”。也许应该如此,但事实是,它本质上具有布局特性,因为随着元素的发展,它应该做一些非常奇怪的事情。在 IE 和 Firefox 之间,

元素上的边距和填充的效果有很大不同。

您是否只想将

内容与框顶部分开?如果是这样,我会尝试使用字段集本身的 padding-top

Well, <legend> really isn't "just another block-level element." Maybe it should be, but the fact is that it inherently is going to have layout peculiarities in that it's supposed to do something pretty weird, as elements go. Between IE and Firefox, the effects of margin and padding on <legend> elements are a lot different.

Do you want to just separate <fieldset> content from the top of the box? If so, I'd try playing with padding-top of the fieldset itself.

旧伤慢歌 2024-09-03 17:08:00

很抱歉发布对这样一个旧线程的答案,但实际上有一个非常简单的解决方案,不需要任何黑客攻击。您所需要做的就是在 fieldset 元素的顶部添加填充。

fieldset { padding: 10px 0 0; }

这可能会让我想说的更清楚: http://jsfiddle.net/8fyvY/

Sorry to post an answer to such an old thread, but there's actually a pretty easy solution for this that doesn't require any hacks. All you need to do is add padding to the top of your fieldset element.

fieldset { padding: 10px 0 0; }

This might make what I'm trying to say a little more clear: http://jsfiddle.net/8fyvY/

骄傲 2024-09-03 17:08:00

我刚刚发现向字段集添加 1px 填充似乎使它突然意识到它包含的边距(创建的间距超过 1 px)。

Ive just found adding a 1px padding to the fieldset seems to make it suddenly aware of the margins it contains (the spacing created is more than 1 px).

难理解 2024-09-03 17:08:00

我遇到了这个问题,在 chrome 上一切看起来都很好,但 safari 却出现了问题。
在这种情况下,如果我添加此代码,

fieldset > legend:first-of-type
{
-webkit-margin-top-collapse: separate;
margin-bottom: 3px;
}

我会在 Chrome 上获得双倍边距。然后决定做以下事情

fieldset > legend + *{
    padding-top:3px;
}

希望有所帮助。干杯!

I meet this problem and everything look fine on chrome but safari make the problem.
In that case if I add this code

fieldset > legend:first-of-type
{
-webkit-margin-top-collapse: separate;
margin-bottom: 3px;
}

I get double margin on Chrome. Then just decide to do the following

fieldset > legend + *{
    padding-top:3px;
}

Hope that help. Cheers!

溺ぐ爱和你が 2024-09-03 17:08:00

为了让图例在所有浏览器中使用底部边框和边距,我在图例内插入一个跨度,将边框放在跨度上,将图例边距设置为 0 并向图例底部添加填充。

例如

legend {
  border: 0;
  margin-bottom: 0;
  padding-bottom: 20px;
}

legend span {
  display: block;
  border-bottom: 2px solid #f0ebe6;
}

To get a legend working with bottom border and margin in all browsers I insert a span inside the legend, put the border on the span, set the legend margin to 0 and add padding to the bottom of the legend.

e.g.

legend {
  border: 0;
  margin-bottom: 0;
  padding-bottom: 20px;
}

legend span {
  display: block;
  border-bottom: 2px solid #f0ebe6;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文