0
0
Bootsrapmarkup~20 mins

Navbar basics in Bootsrap - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Bootstrap Navbar Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
rendering
intermediate
2:00remaining
What is the visual output of this Bootstrap navbar code?
Look at the following Bootstrap navbar code. What will you see when this code runs in a browser?
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>
AOnly the brand name is visible, and the links are always hidden with no toggle button.
BA vertical sidebar with the brand name at the top and three links stacked below it.
CA horizontal navbar with a brand name on the left and three links: Home (highlighted), Features, and Pricing. On small screens, the links collapse behind a toggle button.
DA footer bar with the brand name centered and links aligned to the right.
Attempts:
2 left
💡 Hint
Think about how Bootstrap's navbar-expand-lg and collapse classes work for responsiveness.
selector
intermediate
1:30remaining
Which CSS selector targets only the active link in this Bootstrap navbar?
Given a Bootstrap navbar where the active link has class 'nav-link active', which CSS selector will style only the active link?
A.nav-link:focus
B.nav-item .nav-link
C.navbar-nav > li > a
D.nav-link.active
Attempts:
2 left
💡 Hint
Look for the selector that matches both classes on the same element.
🧠 Conceptual
advanced
1:30remaining
What ARIA attribute improves accessibility for the navbar toggle button?
In a Bootstrap navbar, the toggle button controls showing and hiding the menu on small screens. Which ARIA attribute on the button helps screen readers understand this behavior?
Aaria-expanded
Baria-hidden
Caria-label
Daria-pressed
Attempts:
2 left
💡 Hint
This attribute indicates if the menu is currently open or closed.
layout
advanced
1:30remaining
How does the 'navbar-expand-lg' class affect the navbar layout?
What effect does adding the class 'navbar-expand-lg' have on a Bootstrap navbar's layout?
AThe navbar links are horizontal on large screens and collapse into a toggle menu on smaller screens.
BThe navbar is always vertical regardless of screen size.
CThe navbar links are hidden on large screens and visible only on small screens.
DThe navbar links are always visible and never collapse.
Attempts:
2 left
💡 Hint
Think about how 'expand-lg' controls responsiveness at the large breakpoint.
📝 Syntax
expert
2:00remaining
What error occurs if the toggle button's data-bs-target does not match the collapse div's id?
In this Bootstrap navbar, the toggle button has data-bs-target="#menu" but the collapse div has id="navbarNav". What happens when you click the toggle button?
Bootsrap
<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#menu" aria-controls="menu" 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" href="#">Link</a></li>
    </ul>
  </div>
</nav>
AThe menu opens and closes normally without issues.
BClicking the toggle button does nothing; the menu does not open or close.
CA JavaScript error is thrown in the console.
DThe page reloads unexpectedly.
Attempts:
2 left
💡 Hint
The toggle button must target the correct collapse element by id.