html - 如何通过标签的一部分显示字段集边框?
问题描述
我有一个带有字段集的表单,并希望保留边框,但希望在某些文本图例之间显示边框。我无法让图例具有透明背景以让边框通过(被某些文本元素阻挡)。
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>
解决方案
额外的 div 黑客。如果有办法在没有额外 div 的情况下做到这一点,那就太好了。
我想如果我强制使用 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>
推荐阅读
- html - 如何添加自定义属性和属性
路由器链接? - .net - 如何使用 dotnet CLI(命令行)将项目(.csproj)添加到解决方案文件夹下的解决方案(.sln)?
- java - 性能:内部接口与单独的接口类
- python - 使用 pip 安装 TensorLy 的错误代码
- javascript - 加载和重用图像源 (blob)
- ruby-on-rails - 文件上传后 CarrierWave 不返回 url
- c - SOCK_SEQPACKET Unix Socket 上的空包
- python - 在没有外部功能的情况下旋转图像
- web-scraping - 是否可以抓取网站的脚本并使用 Puppeteer 跟踪它们加载的连续脚本
- html - CSS !important 和内联样式被覆盖