Module 2: CSS (Cascading Style Sheets)

CSS (Cascading Style Sheets) is a stylesheet language used to design and style HTML pages. It controls layout, colors, fonts, spacing, and responsiveness of elements on a webpage.
✅ Separation of Concerns: Keeps design separate from content (HTML).
✅ Improves Design: Enhances website appearance.
✅ Reusability: A single CSS file can be applied to multiple pages.
✅ Responsive Design: Makes web pages adaptable to different screen sizes.
CSS styles are added inside the HTML element using the style attribute.
✅ Quick styling for individual elements
❌ Not reusable and harder to manage for larger projects
Internal CSS applies styles to the entire document from within the <head> section.
✅ Good for styling a single page
❌ Not reusable across multiple pages
External CSS is stored in a separate file (styles.css) and linked to the HTML file.
CSS File (styles.css):
HTML File (index.html):
✅ Best for large projects, keeps styles organized
❌ Requires an extra file
Targets all occurrences of a specific HTML element.
🔹 All <h1> elements will be red
🔹 All <p> elements will have a font size of 18px
Used to style multiple elements with the same class name.
🔹 Use: Add class="highlight" to elements to get the styles
Used for unique elements.
🔹 Use: Add id="header" to a unique element
Applies the same styles to multiple elements.
🔹 Both <h1> and <p> will be centered if it used in the html page
Targets elements inside another element (Nested elements)
🔹 content inside p tag will be purple in color
4. Essential CSS Properties (15 mins)
1️⃣ Colors & Backgrounds
🔹 color: Changes text color
🔹 background-color: Changes background color
2️⃣ Fonts & Text Styling
🔹 font-size: Adjusts text size
🔹 font-family: Changes font
🔹 text-align: Aligns text (left, center, right)
3️⃣ Borders & Spacing
🔹 border: Defines thickness, style, and color
🔹 padding: Space inside an element
🔹 margin: Space outside an element
5. Responsive Design (10 mins)
CSS can make web pages responsive using media queries.
🔹 Changes background color when screen width is 600px or smaller
💡 Task: Create a styled web page using headings, paragraphs, lists, and buttons.
HTML (index.html):
Summary
✅ CSS applies styles to HTML elements
✅ There are 3 ways to apply CSS: Inline, Internal, External
✅ Selectors target elements to apply styles
✅ Media Queries help make pages responsive