A horizontal collapse is a UI feature where content expands or collapses sideways (left to right) instead of vertically. It helps save space and create interactive layouts.
Click to reveal answer
beginner
Which Bootstrap class controls horizontal collapse behavior?
The class .collapse-horizontal enables horizontal collapsing of content in Bootstrap.
Click to reveal answer
intermediate
How do you trigger a horizontal collapse with a button in Bootstrap?
Use a button with data-bs-toggle="collapse" and data-bs-target="#id" attributes. The target element should have collapse collapse-horizontal classes.
Click to reveal answer
intermediate
What CSS property changes during a horizontal collapse animation?
The width property changes from 0 to the element's full width during horizontal collapse animation.
Click to reveal answer
beginner
Why use horizontal collapse instead of vertical collapse?
Horizontal collapse is useful when you want to hide or show side panels or menus without affecting vertical page flow, making layouts more dynamic and space-efficient.
Click to reveal answer
Which class enables horizontal collapse in Bootstrap?
A.collapse-horizontal
B.collapse-vertical
C.horizontal-collapse
D.collapse-side
✗ Incorrect
The correct class is .collapse-horizontal to make the collapse horizontal.
What CSS property animates during horizontal collapse?
Aheight
Bwidth
Copacity
Dmargin
✗ Incorrect
Horizontal collapse changes the width property from 0 to full width.
How do you connect a button to a horizontal collapse element?
AUsing <code>href="#id"</code> only
BUsing <code>onclick="toggle()"</code>
CUsing <code>data-bs-toggle="collapse"</code> and <code>data-bs-target="#id"</code>
DUsing <code>data-toggle="horizontal"</code>
✗ Incorrect
Bootstrap uses data-bs-toggle="collapse" and data-bs-target="#id" to link buttons to collapse elements.
What happens visually when a horizontal collapse is triggered?
AContent expands or shrinks sideways
BContent fades in and out
CContent slides up and down
DContent rotates
✗ Incorrect
Horizontal collapse expands or shrinks content sideways (left to right).
Which Bootstrap version introduced horizontal collapse?
ABootstrap 3
BBootstrap 2
CBootstrap 4
DBootstrap 5
✗ Incorrect
Horizontal collapse was introduced in Bootstrap 5.
Explain how to create a horizontal collapse in Bootstrap and how it differs from a vertical collapse.
Think about the classes and attributes needed and the direction of animation.
You got /4 concepts.
Describe a real-life scenario where horizontal collapse is more useful than vertical collapse.
Consider layouts with side panels or menus.
You got /4 concepts.
Practice
(1/5)
1. What does the collapse-horizontal class do in Bootstrap?
easy
A. It makes the collapsible content slide left or right instead of up or down.
B. It changes the color of the collapsible content.
C. It disables the collapse functionality.
D. It makes the collapsible content slide up or down.
Solution
Step 1: Understand the role of collapse-horizontal
This class changes the collapse animation direction from vertical (up/down) to horizontal (left/right).
Step 2: Compare with default collapse behavior
By default, Bootstrap collapses content vertically. Adding collapse-horizontal changes this to horizontal sliding.
Final Answer:
It makes the collapsible content slide left or right instead of up or down. -> Option A
Quick Check:
collapse-horizontal = horizontal slide [OK]
Hint: Remember: horizontal means left-right slide, not up-down [OK]
Common Mistakes:
Thinking it changes color or disables collapse
Confusing horizontal with vertical collapse
Assuming it works without Bootstrap JS
2. Which of the following is the correct way to start a horizontal collapse in Bootstrap?
easy
A. <div class='collapse-vertical' id='myCollapse'></div>
B. <div class='horizontal-collapse' id='myCollapse'></div>
C. <div class='collapse-horizontal'></div>
D. <div class='collapse collapse-horizontal' id='myCollapse'></div>
Solution
Step 1: Identify correct Bootstrap classes for horizontal collapse
The correct classes are collapse and collapse-horizontal together on the element.
Step 2: Check the syntax of options
<div class='collapse collapse-horizontal' id='myCollapse'></div> uses both classes and includes an id for toggling, which is required for Bootstrap collapse to work.
Final Answer:
<div class='collapse collapse-horizontal' id='myCollapse'></div> -> Option D
Quick Check:
Use both collapse and collapse-horizontal classes [OK]
Hint: Always combine collapse with collapse-horizontal for horizontal effect [OK]
Common Mistakes:
Using only collapse-horizontal without collapse
Using wrong class names like collapse-vertical
Missing the id attribute for toggling
3. Given this code snippet, what will happen when the button is clicked?
C. The id attribute should be on the button, not the div.
D. The collapse-horizontal class should be on the button.
Solution
Step 1: Check required classes for collapse
Bootstrap requires the collapse class on the collapsible element for functionality.
Step 2: Identify missing class in code
The div only has collapse-horizontal but lacks collapse, so it won't collapse properly.
Final Answer:
Missing the main collapse class on the div. -> Option A
Quick Check:
collapse class is mandatory for collapse [OK]
Hint: Always include collapse class with collapse-horizontal [OK]
Common Mistakes:
Forgetting the collapse class
Misplacing id attribute
Assuming button needs collapse-horizontal
5. You want to create a horizontal collapse panel that starts collapsed and expands to 300px wide when toggled. Which code snippet correctly achieves this with accessibility in mind?