CSS3: Cascading Style Sheets
CSS handles text edits, colors, images, spacing, and adaptive layout adjustments.
The Rule of the "Cascade"
Why is it called Cascading Style Sheets? Because the browser reads rules sequentially from top to bottom. If you write conflicting instructions targeting the exact same element, the rule written further down the page wins!
h1 { color: red; }
h1 { color: green; }
/* Every <h1> will be GREEN because that rule cascades DOWN last! */
Connecting CSS to HTML
To tell your HTML structure to inherit your visual choices, paste a stylesheet in the
block right under your<head>
<title>My Webpage</title>
<link rel="stylesheet" href="style.css">
</head>
Target Selectors: Elements, Classes, and IDs
If you style a base HTML tag globally, every single instance of that tag changes on your website. To prevent this from happening, use Classes and IDs to specify your targets with precision.
| Target Type | HTML Implementation | CSS Selection Rule | When to Use It |
|---|---|---|---|
| Element Tag | <h1>Text</h1> |
h1 { ... } |
Global base element styles (e.g., matching all headings layout-wide). |
| Class | <h2 class="sub_heading"> |
.sub_heading { ... } |
Reusable styles you want to apply to multiple items across the site. |
| ID | <i id="italic"> |
#italic { ... } |
Targeting a completely unique element on a specific webpage. |
Naming Convention Rule: When writing class attributes, name them cleanly and consistently using either camelCase (
circleImg) or standard hyphens (circle-img).
Demystifying the CSS Box Model
Every element rendered on a page is treated as an isolated rectangular box. The box model contains four layers:
- Content: The actual image or text inside the tag.
- Padding: The clear interior breathing room inside the element box, separating content from borders.
- Border: The structural framing outlining your container box.
- Margin: The exterior white space pushing away nearby adjacent element boxes.
.containers {
border: 10px solid rgb(36, 103, 105); /* Solid, dotted, or dashed framing options */
margin: 50px 100px; /* Top/Bottom Margin, Left/Right Margin */
padding: 20px 10px; /* Adds clean spacing room inside the box */
background-color: rgb(142, 158, 158); /* Turns container area into a solid layout box */
display: inline-block; /* Controls element distribution (e.g. inline, flex, block) */
}
Responsive Web Design (RWD)
Responsive Web Design (RWD) is a fluid styling methodology that ensures websites automatically adapt across fluctuating device displays. Implementing flexible grids ensures consistent readability whether your visitors browse via desktops, tablets, or mobile smartphones.