Bird
Raised Fist0
Tailwindmarkup~20 mins

Sticky header and footer in Tailwind - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Sticky Layout Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ layout
intermediate
2:00remaining
Sticky Header Behavior
Given this Tailwind CSS code for a header, what will happen when you scroll the page?
Tailwind
<header class="sticky top-0 bg-white shadow p-4">Header Content</header>
AThe header stays visible at the top of the page while scrolling.
BThe header scrolls away with the page content.
CThe header becomes fixed at the bottom of the page.
DThe header disappears when scrolling down and reappears when scrolling up.
Attempts:
2 left
💡 Hint
Think about what the 'sticky' and 'top-0' classes do in Tailwind CSS.
❓ layout
intermediate
2:00remaining
Sticky Footer Positioning
Which Tailwind CSS class combination correctly makes a footer stick to the bottom of the viewport even when the page content is short?
A<footer class="sticky bottom-0 bg-gray-200 p-4">Footer</footer>
B<footer class="absolute bottom-0 bg-gray-200 p-4">Footer</footer>
C<footer class="fixed bottom-0 w-full bg-gray-200 p-4">Footer</footer>
D<footer class="relative bottom-0 bg-gray-200 p-4">Footer</footer>
Attempts:
2 left
💡 Hint
Consider which positioning keeps the footer visible at the bottom regardless of content length.
❓ accessibility
advanced
2:00remaining
Accessible Sticky Header
Which of these code snippets best improves accessibility for a sticky header in Tailwind CSS?
A<header class="sticky top-0 bg-white p-4" role="banner" aria-label="Main site header">Site Header</header>
B<header class="sticky top-0 bg-white p-4" tabindex="-1">Site Header</header>
C<header class="sticky top-0 bg-white p-4" aria-hidden="true">Site Header</header>
D<header class="sticky top-0 bg-white p-4" role="contentinfo">Site Header</header>
Attempts:
2 left
💡 Hint
Think about semantic roles and how screen readers identify page regions.
❓ selector
advanced
2:00remaining
CSS Selector for Sticky Footer
Which CSS selector correctly targets only the footer element with class 'sticky-footer' to apply sticky positioning?
A#sticky-footer { position: sticky; bottom: 0; }
B.sticky-footer footer { position: sticky; bottom: 0; }
Cfooter .sticky-footer { position: sticky; bottom: 0; }
Dfooter.sticky-footer { position: sticky; bottom: 0; }
Attempts:
2 left
💡 Hint
Remember how class selectors and element selectors combine.
🧠 Conceptual
expert
3:00remaining
Sticky Header and Footer Layout Challenge
You want a page with a sticky header at the top, a sticky footer at the bottom, and a scrollable main content area between them. Which Tailwind CSS layout approach achieves this correctly?
A
&lt;div class="flex flex-col h-screen"&gt;
  &lt;header class="sticky top-0 bg-white p-4"&gt;Header&lt;/header&gt;
  &lt;main class="flex-1 overflow-auto p-4"&gt;Content&lt;/main&gt;
  &lt;footer class="sticky bottom-0 bg-gray-200 p-4"&gt;Footer&lt;/footer&gt;
&lt;/div&gt;
B
&lt;div class="flex flex-col h-screen"&gt;
  &lt;header class="fixed top-0 w-full bg-white p-4"&gt;Header&lt;/header&gt;
  &lt;main class="flex-1 overflow-auto p-4 mt-16 mb-16"&gt;Content&lt;/main&gt;
  &lt;footer class="fixed bottom-0 w-full bg-gray-200 p-4"&gt;Footer&lt;/footer&gt;
&lt;/div&gt;
C
&lt;div class="flex flex-col min-h-screen"&gt;
  &lt;header class="sticky top-0 bg-white p-4"&gt;Header&lt;/header&gt;
  &lt;main class="flex-grow overflow-auto p-4"&gt;Content&lt;/main&gt;
  &lt;footer class="sticky bottom-0 bg-gray-200 p-4"&gt;Footer&lt;/footer&gt;
&lt;/div&gt;
D
&lt;div class="grid grid-rows-[auto_1fr_auto] h-screen"&gt;
  &lt;header class="sticky top-0 bg-white p-4"&gt;Header&lt;/header&gt;
  &lt;main class="overflow-auto p-4"&gt;Content&lt;/main&gt;
  &lt;footer class="sticky bottom-0 bg-gray-200 p-4"&gt;Footer&lt;/footer&gt;
&lt;/div&gt;
Attempts:
2 left
💡 Hint
Think about how fixed positioning works and how to prevent content from hiding behind header/footer.

Practice

(1/5)
1. What does the Tailwind class sticky do when applied to a header or footer?
easy
A. It makes the element disappear after scrolling 100px.
B. It hides the element when scrolling down.
C. It keeps the element visible at a fixed position while scrolling.
D. It changes the element's color on scroll.

Solution

  1. Step 1: Understand the sticky class behavior

    The sticky class makes an element stick to a position relative to the viewport when scrolling.
  2. Step 2: Apply to header or footer context

    When used on a header or footer, it keeps that element visible at the top or bottom as the page scrolls.
  3. Final Answer:

    It keeps the element visible at a fixed position while scrolling. -> Option C
  4. Quick Check:

    Sticky = fixed visibility on scroll [OK]
Hint: Sticky means element stays visible while scrolling [OK]
Common Mistakes:
  • Confusing sticky with fixed positioning
  • Thinking sticky hides elements on scroll
  • Assuming sticky changes colors automatically
2. Which Tailwind classes correctly create a sticky footer that stays at the bottom of the viewport?
easy
A. sticky bottom-0
B. sticky top-0
C. fixed bottom-0
D. absolute bottom-0

Solution

  1. Step 1: Identify sticky footer classes

    To make a footer sticky at the bottom, use sticky with bottom-0 so it sticks to the bottom edge.
  2. Step 2: Compare other options

    top-0 sticks to top, fixed is different positioning, and absolute does not stick on scroll.
  3. Final Answer:

    <code>sticky bottom-0</code> -> Option A
  4. Quick Check:

    Sticky + bottom-0 = sticky footer [OK]
Hint: Use sticky with bottom-0 for sticky footer [OK]
Common Mistakes:
  • Using top-0 for footer instead of bottom-0
  • Confusing fixed with sticky positioning
  • Using absolute which doesn't stick on scroll
3. What will happen if you apply sticky top-0 bg-white shadow classes to a header element in Tailwind CSS?
medium
A. The header becomes fixed and covers the whole page.
B. The header scrolls away and has no background or shadow.
C. The header sticks to the bottom with transparent background.
D. The header sticks to the top with white background and shadow while scrolling.

Solution

  1. Step 1: Analyze the classes

    sticky top-0 makes the header stick to the top of the viewport. bg-white sets a white background. shadow adds a subtle shadow.
  2. Step 2: Predict visual effect on scroll

    The header stays visible at the top with white background and shadow as the user scrolls down the page.
  3. Final Answer:

    The header sticks to the top with white background and shadow while scrolling. -> Option D
  4. Quick Check:

    sticky top-0 + bg-white + shadow = sticky visible header [OK]
Hint: sticky top-0 keeps header visible with styles [OK]
Common Mistakes:
  • Thinking sticky hides header on scroll
  • Confusing bottom-0 with top-0
  • Ignoring background and shadow effects
4. You want a sticky header but it disappears behind other content when scrolling. Which Tailwind class should you add to fix this?
medium
A. opacity-50
B. z-50
C. hidden
D. overflow-hidden

Solution

  1. Step 1: Understand the problem

    The sticky header is behind other content, meaning it has a lower stacking order (z-index).
  2. Step 2: Use z-index to fix stacking

    Adding z-50 increases the z-index, bringing the header above other elements.
  3. Final Answer:

    z-50 -> Option B
  4. Quick Check:

    Use z-50 to fix sticky header layering [OK]
Hint: Add z-50 to bring sticky header above content [OK]
Common Mistakes:
  • Using opacity which changes transparency
  • Using hidden which hides the element
  • Using overflow-hidden which clips content
5. You want a page with a sticky header and footer using Tailwind. The header should stick at top, footer at bottom, and main content scrolls between them. Which code snippet correctly implements this?
hard
A.
Header
\n
Content
\n
Footer
B.
Header
\n
Content
\n
Footer
C.
Header
\n
Content
\n
Footer
D.
Header
\n
Content
\n
Footer

Solution

  1. Step 1: Check header and footer sticky positions

    Header
    \n
    Content
    \n
    Footer
    uses sticky top-0 for header and sticky bottom-0 for footer, which is correct for sticky header and footer.
  2. Step 2: Verify main content scroll area

    Main uses overflow-auto and height calculated as full viewport minus header/footer height, allowing scrolling between sticky elements.
  3. Step 3: Compare other options

    Header
    \n
    Content
    \n
    Footer
    uses fixed positioning which overlays content;
    Header
    \n
    Content
    \n
    Footer
    swaps top and bottom for header/footer incorrectly;
    Header
    \n
    Content
    \n
    Footer
    uses absolute which does not stick on scroll.
  4. Final Answer:

    Option A code snippet correctly implements sticky header and footer with scrollable main content. -> Option A
  5. Quick Check:

    Sticky top-0 + sticky bottom-0 + scrollable main = correct layout [OK]
Hint: Use sticky top-0 and bottom-0 with scrollable main [OK]
Common Mistakes:
  • Using fixed instead of sticky causing overlap
  • Swapping top and bottom classes on header/footer
  • Not setting main content height for scrolling
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard