Week 3 Notes
| Site: | Newgate University Minna - Elearning Platform |
| Course: | Introduction to Web Technologies |
| Book: | Week 3 Notes |
| Printed by: | Guest user |
| Date: | Thursday, 20 August 2026, 10:28 PM |
3.1 What is CSS?
CSS (Cascading Style Sheets) controls how HTML content LOOKS. While HTML is the structure (like the bricks of a building), CSS is the finishing — the paint, the tiles, the furniture arrangement. Without CSS, every web page would just be plain black text on a white background.
The word 'Cascading' means that styles can come from multiple sources and they 'cascade' (flow down) with a specific priority. Styles you write yourself override browser defaults.
3.2 Three Ways to Add CSS
|
Method |
How It Works |
When to Use |
Priority |
|
Inline CSS |
Written directly on an HTML element using the style attribute |
Quick testing, one-off overrides |
Highest |
|
Internal CSS |
Written inside a <style> tag in the <head> section |
Single-page websites, small demos |
Medium |
|
External CSS |
Written in a separate .css file, linked to HTML |
ALWAYS preferred for real projects |
Lower (but best practice) |
|
Three Ways to Apply CSS |
|
<!-- 1. INLINE CSS (not recommended for real projects) --> |
|
<p style="color: green; font-size: 18px;">This text is green.</p> |
|
|
|
<!-- 2. INTERNAL CSS (inside <head> of your HTML file) --> |
|
<style> |
|
p { color: blue; font-size: 16px; } |
|
h1 { color: darkred; } |
|
</style> |
|
|
|
<!-- 3. EXTERNAL CSS (the correct, professional approach) --> |
|
<!-- In HTML <head>: --> |
|
<link rel="stylesheet" href="styles.css"> |
|
|
|
/* In styles.css file: */ |
|
p { color: #333333; font-size: 16px; line-height: 1.6; } |
|
h1 { color: #1A3C5E; font-size: 2rem; } |
3.3 CSS Selectors
A selector tells CSS which HTML element(s) to style. Mastering selectors is one of the most important CSS skills.
|
CSS Selectors |
|
/* ELEMENT selector — styles ALL paragraphs */ |
|
p { color: #333; } |
|
|
|
/* CLASS selector — styles elements with class="highlight" */ |
|
.highlight { background-color: yellow; font-weight: bold; } |
|
|
|
/* ID selector — styles ONE element with id="main-title" */ |
|
#main-title { color: darkblue; font-size: 2.5rem; } |
|
|
|
/* DESCENDANT selector — only <a> tags INSIDE a <nav> */ |
|
nav a { color: white; text-decoration: none; } |
|
|
|
/* MULTIPLE selectors — applies same style to h1, h2, and h3 */ |
|
h1, h2, h3 { font-family: 'Arial', sans-serif; } |
|
|
|
/* PSEUDO-CLASS — styles a link when hovered */ |
|
a:hover { color: orange; text-decoration: underline; } |
3.4 The CSS Box Model
Every HTML element is treated as a box. Understanding the box model is fundamental to controlling layout and spacing.
|
📌 IMPORTANT NOTE |
|
The Box Model has 4 layers (from inside to outside): |
|
1. CONTENT — the actual text or image inside the element. |
|
2. PADDING — space between the content and the border (inside the box, same background colour). |
|
3. BORDER — a line around the padding. |
|
4. MARGIN — space outside the border (between this element and its neighbours — transparent). |
|
CSS Box Model Properties |
|
/* Box Model Example */ |
|
.card { |
|
width: 300px; /* Content width */ |
|
padding: 20px; /* Space inside the box */ |
|
border: 2px solid #1A3C5E; /* Visible border */ |
|
margin: 15px; /* Space outside the box */ |
|
background-color: #f0f8ff; /* Background fills content + padding */ |
|
} |
|
|
|
/* Shorthand for padding/margin (top, right, bottom, left — clockwise) */ |
|
.card { padding: 10px 20px 10px 20px; } /* all four sides */ |
|
.card { padding: 10px 20px; } /* top/bottom 10px, left/right 20px */ |
|
.card { padding: 10px; } /* all sides 10px */ |
3.5 Typography, Colours, and Backgrounds
|
Typography, Colours, and Backgrounds |
|
/* TYPOGRAPHY */ |
|
body { |
|
font-family: 'Segoe UI', Arial, sans-serif; /* Font (with fallbacks) */ |
|
font-size: 16px; /* Base size */ |
|
line-height: 1.6; /* Space between lines (1.6x the font size) */ |
|
color: #2C3E50; /* Text colour (dark grey-blue) */ |
|
} |
|
|
|
h1 { |
|
font-size: 2.5rem; /* rem = relative to root font size */ |
|
font-weight: bold; /* normal | bold | 100-900 */ |
|
text-align: center; /* left | center | right | justify */ |
|
text-transform: uppercase; /* none | uppercase | lowercase | capitalize */ |
|
letter-spacing: 2px; /* Space between characters */ |
|
} |
|
|
|
/* COLOURS (CSS accepts: names, hex, rgb, hsl) */ |
|
.header { background-color: #1A3C5E; } /* Hex colour */ |
|
.success { color: rgb(30, 132, 73); } /* RGB colour */ |
|
.warning { color: hsl(45, 80%, 40%); } /* HSL colour */ |
|
|
|
/* BACKGROUNDS */ |
|
.hero { |
|
background-color: #1A3C5E; |
|
background-image: url('campus.jpg'); /* Background image */ |
|
background-size: cover; /* Fills the entire element */ |
|
background-position: center; /* Centers the image */ |
|
} |
3.6 Worked Example — Styled University Homepage
|
Professional Stylesheet — University Homepage |
|
/* ===== styles.css ===== */ |
|
|
|
/* Reset default browser styles */ |
|
* { margin: 0; padding: 0; box-sizing: border-box; } |
|
|
|
body { |
|
font-family: 'Segoe UI', Arial, sans-serif; |
|
font-size: 16px; |
|
color: #2C3E50; |
|
background-color: #f5f7fa; |
|
} |
|
|
|
/* Navigation bar */ |
|
nav { |
|
background-color: #1A3C5E; |
|
padding: 15px 30px; |
|
display: flex; |
|
justify-content: space-between; |
|
align-items: center; |
|
} |
|
|
|
nav .logo { |
|
color: white; |
|
font-size: 1.4rem; |
|
font-weight: bold; |
|
text-decoration: none; |
|
} |
|
|
|
nav a { color: #cce0f0; text-decoration: none; margin-left: 20px; } |
|
nav a:hover { color: white; text-decoration: underline; } |
|
|
|
/* Hero / Banner section */ |
|
.hero { |
|
background-color: #1E8449; |
|
color: white; |
|
text-align: center; |
|
padding: 80px 20px; |
|
} |
|
|
|
.hero h1 { font-size: 3rem; margin-bottom: 15px; } |
|
.hero p { font-size: 1.2rem; max-width: 600px; margin: 0 auto; } |
|
|
|
/* Cards section */ |
|
.card-container { display: flex; gap: 20px; padding: 40px; flex-wrap: wrap; } |
|
|
|
.card { |
|
background: white; |
|
border-radius: 8px; |
|
padding: 25px; |
|
flex: 1; |
|
min-width: 200px; |
|
box-shadow: 0 2px 10px rgba(0,0,0,0.1); |
|
border-top: 4px solid #1E8449; |
|
} |
|
|
|
.card h3 { color: #1A3C5E; margin-bottom: 10px; } |
|
|
|
/* Footer */ |
|
footer { |
|
background-color: #1A3C5E; |
|
color: #aac4d8; |
|
text-align: center; |
|
padding: 20px; |
|
font-size: 0.9rem; |
|
} |
|
Complete HTML using the Stylesheet |
|
<!-- ===== index.html (using the above CSS) ===== --> |
|
<!DOCTYPE html> |
|
<html lang="en"> |
|
<head> |
|
<meta charset="UTF-8"> |
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"> |
|
<title>Newgate University Minna</title> |
|
<link rel="stylesheet" href="styles.css"> |
|
</head> |
|
<body> |
|
|
|
<nav> |
|
<a href="#" class="logo">Newgate University</a> |
|
<div> |
|
<a href="index.html">Home</a> |
|
<a href="about.html">About</a> |
|
<a href="contact.html">Contact</a> |
|
</div> |
|
</nav> |
|
|
|
<div class="hero"> |
|
<h1>Welcome to Newgate University</h1> |
|
<p>Minna, Niger State — Developing tomorrow's technology leaders.</p> |
|
</div> |
|
|
|
<div class="card-container"> |
|
<div class="card"> |
|
<h3>Computing Sciences</h3> |
|
<p>IT, Computer Science, Cyber Security programs</p> |
|
</div> |
|
<div class="card"> |
|
<h3>Student Portal</h3> |
|
<p>Register courses, check results, and pay fees online</p> |
|
</div> |
|
<div class="card"> |
|
<h3>Library</h3> |
|
<p>Access thousands of digital and physical resources</p> |
|
</div> |
|
</div> |
|
|
|
<footer> |
|
<p>© 2024 Newgate University Minna. All rights reserved.</p> |
|
</footer> |
|
|
|
</body> |
|
</html> |