0
0
Bootsrapmarkup~20 mins

Nav tabs and pills in Bootsrap - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Bootstrap Nav 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 nav tabs code?
Look at the following Bootstrap nav tabs code snippet. What will you see rendered in the browser?
Bootsrap
<ul class="nav nav-tabs" role="tablist">
  <li class="nav-item" role="presentation">
    <button class="nav-link active" id="home-tab" data-bs-toggle="tab" data-bs-target="#home" type="button" role="tab" aria-controls="home" aria-selected="true">Home</button>
  </li>
  <li class="nav-item" role="presentation">
    <button class="nav-link" id="profile-tab" data-bs-toggle="tab" data-bs-target="#profile" type="button" role="tab" aria-controls="profile" aria-selected="false">Profile</button>
  </li>
</ul>
AA single button labeled 'Home' with no tabs or pills.
BTwo vertical pills labeled 'Home' and 'Profile' with 'Profile' pill highlighted as active.
CA dropdown menu with options 'Home' and 'Profile'.
DTwo horizontal tabs labeled 'Home' and 'Profile' with 'Home' tab highlighted as active.
Attempts:
2 left
💡 Hint
Remember that 'nav-tabs' class creates horizontal tabs and 'active' class highlights the selected tab.
selector
intermediate
1:30remaining
Which CSS selector targets the active pill in Bootstrap nav pills?
Given Bootstrap nav pills, which CSS selector correctly styles the active pill?
A.nav-pills .nav-link.active
B.nav-tabs .nav-item.active
C.nav-pills .nav-item.selected
D.nav-tabs .nav-link.current
Attempts:
2 left
💡 Hint
Active pills use the 'active' class on the 'nav-link' element inside 'nav-pills'.
🧠 Conceptual
advanced
1:30remaining
What ARIA role should be used on the container of Bootstrap nav tabs for accessibility?
For better accessibility, which ARIA role attribute is recommended on the container element of Bootstrap nav tabs?
Arole="tablist"
Brole="navigation"
Crole="menu"
Drole="listbox"
Attempts:
2 left
💡 Hint
Tabs are a set of related tabs, so the container needs a role that groups them as tabs.
layout
advanced
2:00remaining
How to make Bootstrap nav pills stack vertically on small screens?
You want Bootstrap nav pills to display horizontally on large screens but stack vertically on small screens. Which class combination achieves this?
AAdd 'd-block d-sm-flex' to the nav element
BAdd 'flex-row flex-sm-column' to the nav element
CAdd 'flex-column flex-md-row' to the nav element
DAdd 'flex-column flex-sm-row' to the nav element
Attempts:
2 left
💡 Hint
Use Bootstrap's responsive flex utility classes with the right breakpoint.
📝 Syntax
expert
2:30remaining
What error does this Bootstrap nav tabs code cause?
Examine this Bootstrap nav tabs snippet. What error or issue will it cause when rendered?
Bootsrap
<ul class="nav nav-tabs" role="tablist">
  <li class="nav-item" role="presentation">
    <a class="nav-link active" id="home-tab" data-bs-toggle="tab" href="#home" role="tab" aria-controls="home" aria-selected="true">Home</a>
  </li>
  <li class="nav-item" role="presentation">
    <a class="nav-link" id="profile-tab" data-bs-toggle="tab" href="#profile" role="tab" aria-controls="profile" aria-selected="false">Profile</a>
  </li>
</ul>
<div class="tab-content">
  <div class="tab-pane fade show active" id="home" role="tabpanel" aria-labelledby="home-tab">Home content</div>
  <div class="tab-pane fade" id="profile" role="tabpanel" aria-labelledby="profile-tab">Profile content</div>
</div>
ATabs do not switch content because 'data-bs-toggle' should be 'data-toggle'.
BNo error; tabs work correctly with content switching.
CAccessibility issue: missing 'aria-selected' on active tab link.
DJavaScript error because 'href' attribute is missing on tab links.
Attempts:
2 left
💡 Hint
Bootstrap 5 uses 'data-bs-toggle' and 'href' for tab links to switch content.