我尝试用display: flex和display: inline-flex样式fieldset元素。
然而,它并没有起作用:flex表现得像块,而内联flex表现得像内联块。
火狐和Chrome浏览器都是这样,但奇怪的是IE浏览器却可以。
是bug吗?我找不到fieldset应该有任何特殊的行为,无论是在HTML5还是在CSS Flexible Box Layout规范。
字段集,div {
显示:flex;
边框:1px实体;
}
<自定义字段>
foo < p > < / p >
酒吧< p > < / p >
< /自定义字段>
< div >
foo < p > < / p >
酒吧< p > < / p >
< / div >
根据Bug 984869 - display: flex不适用于按钮元素,
<button> is not implementable (by browsers) in pure CSS, so they are a
bit of a black box, from the perspective of CSS. This means that they
don't necessarily react in the same way that e.g. a <div> would.
This isn't specific to flexbox -- e.g. we don't render scrollbars if
you put overflow:scroll on a button, and we don't render it as a
table if you put display:table on it.
Stepping back even further, this isn't specific to <button>. Consider
<fieldset> and <table> which also have special rendering behavior:
data:text/html,<fieldset style="display:flex"><div>abc</div><div>def</div>
In these cases, Chrome agrees with us and disregards the flex
display mode. (as revealed by the fact that "abc" and "def" end up
being stacked vertically). The fact that they happen to do what you're
expecting on <button style="display:flex"> is likely just due to an
implementation detail.
In Gecko's button implementation, we hardcode <button> (and
<fieldset>, and <table>) as having a specific frame class (and hence,
a specific way of laying out the child elements), regardless of the
display property.
If you want to reliably have the children reliably arranged in a
particular layout mode in a cross-browser fashion, your best bet is to
use a wrapper-div inside the button, just as you would need to inside
of a <table> or a <fieldset>.
因此,该错误被标记为“已解决无效”。
还有Bug 1047590 - display: flex;不工作在<fieldset>,目前“未确认”。
好消息:Firefox 46+实现了<fieldset>的Flexbox。参见bug 1230207。
回答最初的问题:是的,这是一个bug,但在提出问题时并没有明确定义。
现在fieldset的呈现有了更好的定义:https://html.spec.whatwg.org/multipage/rendering.html#the-fieldset-and-legend-elements
在Firefox和Safari中,flexbox on fieldset现在工作。在铬中还没有。(见https://bugs.chromium.org/p/chromium/issues/detail?id=375693)
参见https://blog.whatwg.org/the-state-of-fieldset-interoperability了解2018年规范的改进。