0
0
Bootsrapmarkup~20 mins

Responsive navbar collapse in Bootsrap - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Responsive Navbar Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
rendering
intermediate
2:00remaining
What happens when the navbar toggle button is clicked on a small screen?
Given this Bootstrap navbar code, what is the visible result after clicking the toggle button on a narrow screen?
Bootsrap
<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <a class="navbar-brand" href="#">Brand</a>
  <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>
  <div class="collapse navbar-collapse" id="navbarNav">
    <ul class="navbar-nav">
      <li class="nav-item">
        <a class="nav-link active" aria-current="page" href="#">Home</a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="#">Features</a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="#">Pricing</a>
      </li>
    </ul>
  </div>
</nav>
AThe menu items slide down and become visible below the toggle button.
BThe navbar disappears completely from the screen.
CNothing changes; the menu items remain hidden.
DThe toggle button changes color but the menu stays hidden.
Attempts:
2 left
💡 Hint
Think about what the 'collapse' class does when toggled.
selector
intermediate
1:30remaining
Which Bootstrap class controls when the navbar expands?
In the class attribute 'navbar-expand-lg', what does 'lg' specify?
A'lg' means the navbar expands only on small screens (<576px).
B'lg' means the navbar is always expanded regardless of screen size.
C'lg' means the navbar expands on large screens and above (≥992px).
D'lg' means the navbar never expands and is always collapsed.
Attempts:
2 left
💡 Hint
Bootstrap uses size abbreviations like sm, md, lg, xl to control responsiveness.
🧠 Conceptual
advanced
1:30remaining
Why is the aria-expanded attribute important on the navbar toggle button?
What role does aria-expanded="false" play in the toggle button for accessibility?
AIt tells screen readers whether the menu is currently visible or hidden.
BIt changes the button color when clicked.
CIt disables the toggle button when the menu is open.
DIt automatically closes the menu after 5 seconds.
Attempts:
2 left
💡 Hint
Think about how screen readers understand interactive elements.
📝 Syntax
advanced
1:30remaining
What error occurs if the data-bs-target attribute is missing on the toggle button?
Consider this toggle button missing data-bs-target. What happens when clicked?
Bootsrap
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
  <span class="navbar-toggler-icon"></span>
</button>
AA JavaScript error is thrown in the console.
BClicking the button does nothing; the menu does not collapse or expand.
CThe page reloads unexpectedly.
DThe menu expands but with broken styling.
Attempts:
2 left
💡 Hint
The toggle button needs to know which element to control.
layout
expert
2:00remaining
How to ensure the navbar toggle button is keyboard accessible?
Which practice makes the toggle button fully accessible via keyboard navigation?
AUse a <span> with a click event and no tabindex.
BUse a <div> with onclick and tabindex="-1".
CUse an <a> tag without href but with role="button".
DUse a <button> element with aria-label and ensure it is focusable.
Attempts:
2 left
💡 Hint
Think about semantic HTML and keyboard focus.