This tutorial is designed to help you understand and effectively use Bootstrap's color and background utilities. By the end of this tutorial, you will be able to choose appropriate colors for your webpages, apply background colors, and create a consistent color scheme throughout your website using Bootstrap.
Prerequisites:
- Basic knowledge of HTML and CSS.
- Familiarity with Bootstrap framework.
Bootstrap offers a wide range of color and background classes which can be used to change the text color, background color, link color, etc. It includes color classes for typography, background, borders, and other components.
Bootstrap includes classes for setting text and link colors. The classes .text-{color}
and .text-{context}
can be used to set the color of text, where {color}
can be any of Bootstrap’s color names (like danger
, success
, dark
, etc.) and {context}
is for contextual classes (like primary
, secondary
, info
, etc.)
Bootstrap also includes background color classes. The .bg-{color}
and .bg-{context}
classes are used to set the background color of an element, where {color}
can be any of Bootstrap's color names and {context}
is for contextual classes.
Here's how you can change the color of text in Bootstrap:
<!-- This will make the text color red -->
<p class="text-danger">This is a danger paragraph.</p>
<!-- This will make the text color green -->
<p class="text-success">This is a success paragraph.</p>
Here's how you can change the background color of an element in Bootstrap:
<!-- This will make the background color red -->
<div class="bg-danger">This is a danger div.</div>
<!-- This will make the background color green -->
<div class="bg-success">This is a success div.</div>
Congratulations, you've learned how to work with color and background utilities in Bootstrap! You can now use these utilities to enhance the look of your webpages and create a consistent color scheme across your website.
Next, you might want to dive deeper into Bootstrap and learn about its other components, like buttons, forms, and navbars.
Solutions:
1.
<div class="bg-primary text-white">This is a webpage with a blue background and white text.</div>
<div class="bg-primary">This is the first section with a blue background.</div>
<div class="bg-danger">This is the second section with a red background.</div>
<div class="bg-success">This is the third section with a green background.</div>
<p class="text-primary">This is a paragraph with blue text.</p>
<p class="text-danger">This is a paragraph with red text.</p>
<p class="text-success">This is a paragraph with green text.</p>