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.

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;.

Apparently the browsers don’t like to set the fieldset height to actually 0 (zero), if a legend exists.

So the animations runs till only the legend is visible and then show/hide the fieldset.

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

EDIT: Solution

Rip the legend out of the fieldset with float. Solution within the codepen. Thanks @beni-sinca

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

This is an old topic. <legend> elements were always very vague and there were very many browser inconsistencies around <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%;
}


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x