简体   繁体   English

如何通过label的一部分显示fieldset边框?

[英]How to show the fieldset border through a section of the label?

I have a form with fieldsets, and would like to keep the border, but would like the border to be shown between some text legends.我有一个带有字段集的表单,并希望保留边框,但希望在某些文本图例之间显示边框。 I can't get the legend to have a transparent background to let the border through (to be blocked by some text elements).我无法让图例具有透明背景以让边框通过(被某些文本元素阻挡)。

 legend { display:flex; justify-content:space-between; width: 100%; background-color: transparent; } legend div { background-color: white; margin-left:0.5em; margin-right:0.5em; }
 <form> <fieldset> <legend><div>Form Item</div><div>(extra 1)</div></legend> <label>Input:</label><input></input> </fieldset> </form>

Extra div hack.额外的 div 黑客。 If there is a way to do this without the extra div, that would be great.如果有办法在没有额外 div 的情况下做到这一点,那就太好了。

I guess if I force the fieldset border (chrome's default border is 2px groove threedface), it works ok.我想如果我强制使用 fieldset 边框(chrome 的默认边框是 2px 凹槽三面),它可以正常工作。

 fieldset { border: 1px solid black; } legend { display:flex; justify-content:space-between; width: 100%; position: relative; } legend div { background-color: white; margin-left:0.5em; margin-right:0.5em; } legend div.line { flex: 1 1 auto; background-color: transparent; } legend div.line:before { position: absolute; z-index: -1; content: ''; left: 0px; right: 0px; top: 50%; border-top: 1px solid black; }
 <form> <fieldset> <legend><div>Form Item</div><div class="line"></div><div>(extra 1)</div></legend> <label>Input:</label><input></input> </fieldset> </form>

background can approximate this without an extra div. background 可以在没有额外 div 的情况下近似此值。 You simply need to find the correct color:您只需要找到正确的颜色:

 fieldset { border: 1px solid black; } legend { display: flex; justify-content: space-between; width: 100%; background: linear-gradient(black 0 0)center/100% 1px no-repeat; } legend div { background-color: white; padding:0 0.5em; }
 <form> <fieldset> <legend> <div>Form Item</div> <div>(extra 1)</div> </legend> <label>Input:</label><input> </fieldset> </form>

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

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