Basic text and box model styling
We’ve covered the fundamentals of CSS3, syntax, and linking stylesheets. Now, let’s explore some practical applications with text and box model styling.
Text Styling:
-
Font Properties: Control the appearance of text using properties like font-family (specifying fonts), font-size (adjusting text size), and color (setting text color).
-
Text Decoration: Add emphasis or style text with properties like text-decoration (underlines, strikethroughs) and text-transform (uppercase, lowercase, capitalization).
-
Text Alignment: Control how text aligns within its container using text-align (left, right, center, justify).
Example (styles.css):
h1 { font-family: Georgia, serif; font-size: 1.8em; color: #333; text-align: center;}
p { font-family: Arial, sans-serif; font-size: 1em; line-height: 1.5; /* Adjust line spacing */}Box Model Styling:
The CSS box model defines how elements are laid out on a web page. It consists of four components:
- Content: The actual text, images, or other content within the element.
- Padding: The space between the content and the border.
- Border: The optional decorative line around the element.
- Margin: The space outside the border of the element.
We can use CSS properties to style each of these components:
- Padding: Use padding properties (e.g., padding-top, padding-left) to add space around the content.
- Border: Define border style, width, and color using border properties (e.g., border-style, border-width, border-color).
- Margin: Control the margin around the element using margin properties (similar to padding).
Example (styles.css):
.box { margin: 20px; /* Add margin around the element */ padding: 10px; /* Add padding around the content */ border: 1px solid #ccc; /* Set a thin gray border */}Combining Styles:
You can combine text and box model properties within a single rule to achieve a specific look.
Example (styles.css):
.important {font-weight: bold; /_ Make text bold _/color: red;background-color: #f0f0f0;padding: 5px;border: 2px dashed orange;}By mastering these basic styling techniques, you can significantly enhance the visual presentation and readability of your web pages, and this shows you are already becoming the Highly Performant and Efficient Software Engineer we want to mold you into.