Basic CSS Styling
Introduction and Overview
Hello, budding programmers!
A website without styling is like a tree without leaves—it’s useful, but it doesn’t appear as attractive as it could be. That’s where CSS, short for Cascading Style Sheets, steps in. Creating websites is not just about surrounding content with HTML tags; it’s also about making it pleasing to the eye, easier to read, and user-friendly, which is what CSS is all about. CSS is used widely in the real world to create visually appealing and user-friendly websites like Facebook, Google, and even this learning platform.
Today, we will learn the basics of CSS and how to apply it to our HTML to-do list that we've built in the previous lessons. By the end of this lesson, you'll be able to make your to-do list not just functional, but also attractive!
Understanding CSS
CSS gives life to your HTML pages—it stores rule sets that decide how your HTML elements should look. Just like HTML, CSS is not a programming language; it's a stylesheet language that describes the look and formatting of an HTML document.
CSS is cascading because styles come "trickling down" from top to bottom. If more than one style applies to an HTML element, the style closest to that element will take priority. This is also known as the rule of "specificity." Think of it like house painting rules: You might say all new houses should be painted red, unless they have a porch, in which case they should be yellow. Furthermore, if the house has the number 14, it should be green. This hierarchy can be understood as red<yellow<green, with the most specific rule (green) taking precedence.
Introduction to Inline and Internal CSS
Inline CSS involves adding style rules directly into an HTML element’s style attribute. It’s handy for small, one-off styling needs, but isn’t always the best choice because it doesn’t promote code reuse.
When we talk about internal CSS, we’re referring to style rules that are placed inside a <style> tag within the <head> section of an HTML document. Internal CSS is a better choice when you need to style multiple elements or the entire page.
Remember, for our lessons, we want to focus on understanding these concepts without relying on external stylesheets, so stick to inline and internal CSS!
