CSS (Cascading Style Sheets) is the language we use to style the visual presentation of web pages. It separates design from structure, making websites beautiful and maintainable.
1The Architecture of Style
A CSS rule is a declaration of intent.
- βThe Selector: Tells the browser WHICH element to look for (e.g.,
h1,.button,#logo). - βThe Declaration Block: Wrapped in curly braces
{ }, this contains one or more property/value pairs. - βProperties: Predefined keywords like
color,margin, orfont-size. - βValues: The settings you apply, like
32pxor#FF0099. Every declaration MUST end with a semicolon (;).
2Cascade Control
Why the name 'Cascading'? Because rules flow from top to bottom.
- βExternal Link: The gold standard. Keeps styles in a separate
.cssfile for site-wide consistency. - βInternal Style: Placed in the
<style>tag within the HTML<head>. Good for single-page overrides. - βSpecificity: This is the 'weight' of a selector. An ID is worth more than a Class, which is worth more than a Tag. If specificity is equal, the last rule written in the code is the one the browser applies.
