简体   繁体   English

带有字段集的 flexbox CSS 不一致,Firefox 与 Chrome

[英]Inconsistent flexbox CSS with fieldsets, Firefox vs. Chrome

I've encountered some weird behavior that I would appreciate getting explained or cleared up.我遇到了一些奇怪的行为,希望得到解释或澄清。 Am I perhaps using flex wrong?我可能使用 flex 错误吗?

https://jsfiddle.net/bxnohfkq/5/ https://jsfiddle.net/bxnohfkq/5/

 let $field = $('#field'); let $wrapper = $('#wrapper'); let $button = $('#button'); // display dimensions. $field.val($wrapper.outerWidth() + '×' + $wrapper.outerHeight()); // ??? $button.click((ev) => { if ($wrapper.is('.fix')) { $wrapper.removeClass('fix'); } else { $wrapper.addClass('fix'); } });
 * { box-sizing: border-box; } fieldset { min-width: 0; padding: 0; margin: 0; border: 0; } #wrapper { max-width: 260px; } #padded { padding: 0.5rem; background-color: tan; } #row { display: flex; } #fieldset_field { flex-grow: 1; } #field { width: 100%; } #button { margin-left: 0.5rem; } .fix fieldset { min-inline-size: unset; }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div id="wrapper"> <p>Clicking button fixes the issue in Firefox. In Chrome, it never even comes up in the first place.</p> <div id="padded"> <div id="row"> <fieldset id="fieldset_field"> <input type="text" id="field" /> </fieldset> <fieldset id="fieldset_button"> <button id="button">Ok</button> </fieldset> </div> </div> </div>

I have an input field that pushes a neighboring button out of its wrapper box – but only in Firefox;我有一个输入字段,可以将相邻按钮从包装盒中推出——但仅限于 Firefox; Chrome doesn't have that issue. Chrome 没有这个问题。

At first, I thought it had something to do with how the user agents use different default widths for the form input field.起初,我认为这与用户代理如何为表单输入字段使用不同的默认宽度有关。 But it turned out to be a <fieldset> setting: it aligns nicely if I apply min-inline-size: unset;但结果证明它是一个<fieldset>设置:如果我应用min-inline-size: unset;它会很好地对齐min-inline-size: unset; or min-inline-size: min-content;min-inline-size: min-content; to all fieldsets.到所有字段集。

Though, I do not really understand the underlying issue.虽然,我并不真正理解潜在的问题。 Documentation suggests that that attribute only ever becomes relevant in regards to the writing direction – which I'm not changing in any way. 文档表明,该属性只会与写作方向相关——我不会以任何方式改变这一点。

You may use flex: 1 1 0;您可以使用flex: 1 1 0; ( flex: [grow] [shrink] [base]; ) instead of only flex-grow: 1; ( flex: [grow] [shrink] [base]; ) 而不是只有flex-grow: 1; , this way you can also remove the min-inline-size . ,这样您还可以删除min-inline-size

 * { box-sizing: border-box; } fieldset { min-width: 0; padding: 0; margin: 0; border: 0; } #wrapper { max-width: 260px; } #padded { padding: 0.5rem; background-color: tan; } #row { display: flex; } #fieldset_field { flex: 1 1 0; } #field { width: 100%; } #button { margin-left: 0.5rem; }
 <div id="wrapper"> <p>Clicking button fixes the issue in Firefox. In Chrome, it never even comes up in the first place.</p> <div id="padded"> <div id="row"> <fieldset id="fieldset_field"> <input type="text" id="field" /> </fieldset> <fieldset id="fieldset_button"> <button id="button">Ok</button> </fieldset> </div> </div> </div>

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

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