0
0
Tailwindmarkup~20 mins

Container utility for centering in Tailwind - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Centering Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
layout
intermediate
2:00remaining
Center a div horizontally using Tailwind
You want to center a <div> horizontally inside its parent container using Tailwind CSS. Which utility class should you add to the div?
Tailwind
<div class="?">Centered content</div>
Atext-center
Bmy-auto
Cmx-auto
Ditems-center
Attempts:
2 left
💡 Hint
Think about margin utilities that control horizontal spacing.
layout
intermediate
2:00remaining
Vertically and horizontally center content with Tailwind
You want to center a <div> both vertically and horizontally inside a parent container using Tailwind CSS. The parent has a fixed height. Which set of classes on the parent will achieve this?
Tailwind
<div class="?" style="height: 300px;"><div>Centered content</div></div>
Aflex justify-center items-center
Bblock mx-auto my-auto
Cflex justify-center my-auto
Dgrid place-items-center
Attempts:
2 left
💡 Hint
Use flexbox utilities that align items both ways.
selector
advanced
1:30remaining
Which Tailwind class centers text inside a container?
You want to center the text inside a <div> horizontally. Which Tailwind utility class will do this?
Tailwind
<div class="?">This text should be centered</div>
Atext-center
Bmx-auto
Citems-center
Djustify-center
Attempts:
2 left
💡 Hint
Think about text alignment utilities.
accessibility
advanced
2:30remaining
Accessible centering of main content with Tailwind
You want to center the main content both vertically and horizontally on the page using Tailwind CSS. Which approach ensures the content is centered and accessible with proper semantic HTML?
Tailwind
<main class="?">Main content</main>
Aflex justify-center items-center min-h-screen
Bflex justify-center items-center h-screen
Cgrid place-items-center h-full
Dblock mx-auto my-auto h-screen
Attempts:
2 left
💡 Hint
Use full viewport height and flexbox for centering.
🧠 Conceptual
expert
3:00remaining
Why does mx-auto center block elements but not inline elements?
In Tailwind CSS, the utility mx-auto centers block elements horizontally by setting left and right margins to auto. Why does this not work to center inline elements like <span>?
ABecause <code>mx-auto</code> sets padding, not margin, which inline elements ignore
BBecause <code>mx-auto</code> only works inside flex containers
CBecause inline elements have fixed width and cannot be centered
DBecause inline elements ignore margin properties and need text alignment instead
Attempts:
2 left
💡 Hint
Think about how inline elements handle margins and alignment.