🎯 Learning Objectives
- Understand what CSS is and its purpose
- Learn CSS syntax, selectors, and properties
- Apply inline, internal, and external CSS
- Use Chrome DevTools for live CSS editing
- Style the news page from Day 1
🎨 What is CSS?
CSS (Cascading Style Sheets) is a stylesheet language used to describe the presentation of HTML documents.
CSS controls:
- Colors and backgrounds
- Fonts and text styling
- Spacing (margins, padding)
- Layout and positioning
- Animations and transitions
Why Use CSS?
- Separation of concerns: Keep content (HTML) separate from presentation (CSS)
- Consistency: Apply same styles across multiple pages
- Maintainability: Change design without touching HTML
- Efficiency: One CSS file can style entire website
📝 CSS Syntax
Example:
- Selector: What element to style (h1)
- Property: What aspect to change (color)
- Value: The specific setting (blue)
🔗 Three Ways to Add CSS
1. Inline CSS (Not Recommended)
Applied directly to an element using the style attribute.
⚠️ Avoid inline CSS - It's hard to maintain and mixes content with presentation.
2. Internal CSS (For Single Pages)
Written in the <style> tag within the <head> section.
3. External CSS (Best Practice) ✅
Written in a separate .css file and linked to HTML.
🎯 CSS Selectors
1. Element Selector
Selects all <p> elements.
2. Class Selector (.)
3. ID Selector (#)
💡 Classes vs IDs:
- Use classes for multiple elements
- Use IDs for unique elements (only once per page)
4. Multiple Selectors
5. Descendant Selector
Selects all <p> elements inside <article>.
🎨 Common CSS Properties
Text Styling
| Property | Values | Example |
|---|---|---|
| color | red, #ff0000, rgb(255,0,0) | color: blue; |
| font-size | 16px, 1.5em, 100% | font-size: 20px; |
| font-family | Arial, serif, sans-serif | font-family: Arial; |
| font-weight | normal, bold, 700 | font-weight: bold; |
| text-align | left, center, right, justify | text-align: center; |
| text-decoration | underline, none, line-through | text-decoration: none; |
Background Properties
Colors in CSS
Named Colors: red
Hex Colors: #3498db
RGB: rgb(52, 152, 219)
RGBA (with transparency): rgba(52, 152, 219, 0.5)
Spacing: Margin and Padding
Borders
🛠️ Chrome DevTools for CSS
How to Use DevTools:
- Right-click on any element → "Inspect"
- Or press F12 or Ctrl+Shift+I
- Select the Elements tab
- View and edit CSS in real-time
- See the box model (margin, padding, border)
💡 Pro Tip: Changes in DevTools are temporary - copy them to your CSS file!
💻 Main Activity: Style Your News Page
Task: Create style.css and link to news-article.html
Create a new file: C:\xampp\htdocs\web_basics\css\style.css
Step 1: Link CSS to HTML
Add this in the <head> of news-article.html:
Step 2: Create style.css
✏️ Practice Exercises
Exercise 1: Experiment with Colors
Change the following in your CSS:
- Try different background colors for header
- Change text colors
- Add a gradient background to body
- Use rgba() for transparent effects
Exercise 2: Typography
- Change font families (try: 'Georgia', 'Courier New', 'Times New Roman')
- Adjust font sizes
- Add letter-spacing and line-height
- Experiment with font-weight
Exercise 3: Spacing and Borders
- Add margins and padding to different elements
- Create bordered boxes with border-radius
- Add box-shadow to elements
Exercise 4: Style Your Profile Page
Go back to profile.html from Week 1 and create a separate CSS file for it.
- Style headings with colors
- Add borders and padding to sections
- Style links (change color, remove underline, add hover effect)
- Make the profile image circular
📝 CSS Cheat Sheet
Common Properties Quick Reference:
✅ Today's Deliverable
- style.css file with comprehensive styling
- Styled news-article.html page
- Styled profile.html page with separate CSS
- Screenshots of before and after styling
- Committed and pushed to GitHub with message: "Add CSS styling"