简体   繁体   English

不能设置高度:0; 如果图例可用,则到字段集

[英]Can't set height: 0; to fieldset if legend is available

Background背景

I have a form with collapsible fieldsets.我有一个带有可折叠字段集的表单。 In this example, each checkbox opens a fieldset with help of Bootstrap-Collapse.在这个例子中,每个复选框在 Bootstrap-Collapse 的帮助下打开一个字段集。

https://codepen.io/vacoxudelpen/full/LYjOryP https://codepen.io/vacoxudelpen/full/LYjOryP

The Odd奇数

The fieldset with legend don't (un)collapse smoothly.带有图例的字段集不会(取消)顺利折叠。 The fieldset without legend is fine.没有图例的字段集很好。

The Known已知的

Bootstrap animates the collapse-elements with overflow: hidden; height: 0; Bootstrap 使用overflow: hidden; height: 0;对折叠元素进行动画处理overflow: hidden; height: 0; overflow: hidden; height: 0; . .

Apparently the browsers don't like to set the fieldset height to actually 0 (zero), if a legend exists.显然,如果存在图例,浏览器不喜欢将字段集高度设置为实际 0(零)。

So the animations runs till only the legend is visible and then show/hide the fieldset.所以动画一直运行到只有图例可见,然后显示/隐藏字段集。

展示 Firefox 在这种情况下如何解释高度 0

This is an old topic.这是一个老话题。 <legend> elements were always very vague and there were very many browser inconsistencies around <legend> . <legend>元素总是非常模糊,并且在<legend>周围有很多浏览器不一致的地方。

I funny enough had a similar task once and managed to fix it by floating the legend element and making sure it has the right width.有趣的是,我曾经有过一次类似的任务,并设法通过浮动图例元素并确保它具有正确的宽度来修复它。

In your case I think something like this would do the job:在你的情况下,我认为这样的事情可以完成这项工作:

legend.col-form-label {
    float: left;
    width: 100%;
    max-width: 100%;
    flex: 0 0 100%;
}

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

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