A. The scrollable container #scrollArea needs a fixed height and overflow set
B. The nav element must be outside the scrollable container
C. The data-bs-target should point to #scrollArea, not #menu
D. The href attributes in nav links must be full URLs
Solution
Step 1: Check ScrollSpy container requirements
ScrollSpy requires the scrollable container to have a fixed height and overflow: auto or scroll to detect scrolling.
Step 2: Identify missing CSS for #scrollArea
The code lacks CSS to make #scrollArea scrollable, so ScrollSpy won't work properly.
Final Answer:
The scrollable container #scrollArea needs a fixed height and overflow set -> Option A
Quick Check:
Scrollable container needs height + overflow [OK]
Hint: Scrollable container must have fixed height and overflow [OK]
Common Mistakes:
Not setting height and overflow on scroll container
Placing nav outside scroll container unnecessarily
Using wrong data-bs-target attribute
Using full URLs in href instead of section IDs
5. You want to use ScrollSpy on a page with a fixed top navbar and multiple sections. Which combination of steps is correct to ensure ScrollSpy works properly?
hard
A. Add data-bs-spy="scroll" on navbar, set overflow: hidden; on body, and use full URLs in navbar links
B. Add data-bs-spy="scroll" and data-bs-target on body, set position: relative; on body, and ensure navbar links match section IDs
C. Add data-bs-spy="scroll" on each section, set position: fixed; on navbar, and use # only in links
D. Add data-bs-spy="scroll" on html, set overflow: scroll; on navbar, and use external links in navbar
Solution
Step 1: Enable ScrollSpy on the scroll container
Usually, body is the scroll container, so add data-bs-spy="scroll" and data-bs-target there.
Step 2: Set position: relative; on the scroll container
ScrollSpy requires the scroll container to have position: relative; for correct offset calculations.
Step 3: Ensure navbar links correspond to section IDs
Links in the navbar must have hrefs matching the IDs of the page sections for ScrollSpy to highlight correctly.
Final Answer:
Add data-bs-spy="scroll" and data-bs-target on body, set position: relative; on body, and ensure navbar links match section IDs -> Option B
Quick Check:
ScrollSpy setup = data attributes + position + matching links [OK]
Hint: Set data attributes on body, position relative, matching hrefs [OK]
Common Mistakes:
Adding data-bs-spy on wrong elements
Forgetting position: relative on scroll container
Using full URLs instead of section IDs in links
Setting overflow on navbar instead of scroll container
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.