Component-based frameworks help build websites by breaking the page into small, reusable parts. This makes building and fixing websites easier and faster.
When you want to reuse buttons or menus on many pages without rewriting code.
When building a website with many repeating sections like cards or alerts.
When working with a team so everyone can work on different parts without confusion.
When you want to keep your website organized and easy to update.
When you want to quickly change the look of many parts by editing just one component.
Syntax
Bootsrap
<div class="component-name">
<!-- component content here -->
</div>
Bootstrap provides ready-made components like buttons, cards, and navbars using specific class names.
You add these classes to HTML elements to use the component styles and behavior.
Examples
This creates a blue button using Bootstrap's button component classes.
Bootsrap
<button class="btn btn-primary">Click me</button>
This shows a green alert box to give positive feedback to users.
Bootsrap
<div class="alert alert-success" role="alert">
Success! Your action worked.
</div>
This creates a navigation bar at the top of the page with a light background.
This example shows a simple webpage using Bootstrap components: a colored header, a green button, a warning alert, a card with a title and button, and a footer. Each part is a reusable component styled by Bootstrap classes.
5. You want to create a reusable Bootstrap card component that shows a title and text. Which approach best follows the component-based philosophy?
hard
A. Use Bootstrap card classes and create a reusable template or component in your code
B. Create a custom CSS class and write card HTML manually each time
C. Write the card HTML once and copy-paste it everywhere
D. Avoid using Bootstrap and write all styles inline
Solution
Step 1: Understand component-based philosophy
It encourages reusable parts that can be used multiple times without rewriting code.
Step 2: Evaluate options for reusability and Bootstrap usage
Use Bootstrap card classes and create a reusable template or component in your code uses Bootstrap classes and creates a reusable template/component, which is best practice.
Final Answer:
Use Bootstrap card classes and create a reusable template or component in your code -> Option A
Quick Check:
Reusable templates + Bootstrap classes = best practice [OK]
Hint: Reuse Bootstrap classes with templates/components [OK]
Common Mistakes:
Copy-pasting code instead of reusing components
Writing custom CSS unnecessarily
Avoiding Bootstrap and inline styles
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.