Cards help organize content into neat boxes with a header, body, and footer. This makes information easy to read and visually clear.
Card structure (header, body, footer) in Bootsrap
<div class="card"> <div class="card-header">Header content</div> <div class="card-body">Body content</div> <div class="card-footer">Footer content</div> </div>
The card-header is for the top part, usually a title or label.
The card-body holds the main content like text or images.
<div class="card"> <div class="card-header">Profile</div> <div class="card-body">Name: Jane Doe</div> <div class="card-footer">Contact: jane@example.com</div> </div>
<div class="card"> <div class="card-body">Just body content without header or footer.</div> </div>
<div class="card"> <div class="card-header">Product</div> <div class="card-body"> <h5 class="card-title">Coffee Mug</h5> <p class="card-text">A nice mug for your coffee.</p> </div> <div class="card-footer">$9.99</div> </div>
This example shows a Bootstrap card with a header, body, and footer inside a container. The card is limited in width for better reading on larger screens.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>Bootstrap Card Example</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet" /> </head> <body> <main class="container my-4"> <section class="card" style="max-width: 20rem;"> <div class="card-header">User Profile</div> <div class="card-body"> <h5 class="card-title">Jane Doe</h5> <p class="card-text">Web developer and coffee lover.</p> </div> <div class="card-footer text-muted">Contact: jane@example.com</div> </section> </main> </body> </html>
Use text-muted class in footer to make text lighter and less distracting.
Cards are responsive and adjust nicely on small screens.
You can add images inside card-body or use card-img-top for images above the header.
Cards organize content into header, body, and footer sections.
Bootstrap provides easy classes to style these parts consistently.
Cards improve readability and layout on all screen sizes.
Practice
Solution
Step 1: Understand Bootstrap card parts
Bootstrap cards have specific classes for each part: header, body, and footer.Step 2: Identify the header class
The classcard-headeris used to style the header section of a card.Final Answer:
card-header-> Option BQuick Check:
Header section class =card-header[OK]
card-header class [OK]- Confusing
card-titlewith header - Using non-existent classes like
card-top - Mixing header with body or footer classes
Solution
Step 1: Identify the correct tag and class for card body
Bootstrap uses adivwith classcard-bodyto hold the main content.Step 2: Check the options for correct syntax
<div class='card-body'>Content</div>uses<div class='card-body'>, which is the standard Bootstrap structure.Final Answer:
<div class='card-body'>Content</div> -> Option AQuick Check:
Card body usesdiv.card-body[OK]
div with class card-body [OK]- Using wrong tags like
sectionorbody - Using incorrect class names like
card-content - Placing content outside the card body div
<div class='card'> <div class='card-footer'>Footer</div> <div class='card-header'>Header</div> <div class='card-body'>Body</div> </div>
Solution
Step 1: Understand Bootstrap card layout
Bootstrap .card uses display: flex; flex-direction: column, so visual order matches HTML DOM order.Step 2: Trace the HTML source order
Footer div first, then header, then body. No CSS reordering occurs.Step 3: Understand visual stacking
Flex-direction: column stacks children vertically in source order, so footer appears at top, which is unusual.Step 4: Bootstrap expects header first, then body, then footer for correct visual order
Since the HTML places footer first, it will appear at top, which is not standard.Final Answer:
Footer, Header, Body -> Option DQuick Check:
Visual order = Footer, Header, Body [OK]
- Assuming Bootstrap reorders to header-body-footer regardless of HTML
- Thinking CSS order properties override DOM order
- Ignoring flex-direction: column stacks in source order
<div class='card'> <div class='card-header'>Title</div> <div class='card-body'>Content</div> <div class='card-footer'>Footer</div> </div>
What is wrong?
Solution
Step 1: Check container class
The outerdivhas classcard, which is correct.Step 2: Verify card parts order and nesting
Header, body, and footer are correctly placed as siblings inside the card container.Final Answer:
No error; this is correct Bootstrap card structure -> Option CQuick Check:
Proper card structure = No error [OK]
div.card [OK]- Thinking footer must come before body
- Placing header inside body incorrectly
- Forgetting the main card container class
Solution
Step 1: Use
The footer must have thecard-footerfor footer sectioncard-footerclass to style it as a card footer.Step 2: Align button right using Flexbox utilities
Bootstrap'sd-flexmakes the footer a flex container, andjustify-content-endpushes content to the right.Final Answer:
card-footer d-flex justify-content-end-> Option AQuick Check:
Right aligned footer button =d-flex justify-content-end[OK]
- Using deprecated
float-rightclass - Using
text-centerwhich centers content - Using
align-items-startwhich aligns vertically
Ready to prove it?
Pass the test and this pattern moves unknown
