CSS 01 - 075655
CSS 01 - 075655
✅ What is CSS?
CSS (Cascading Style Sheets) is a language used to describe the presentation (look and formatting) of a
webpage written in HTML.
HTML = Structure
CSS = Styling / Presentation
It controls:
• Layout
• Colors
• Fonts
• Spacing
• Animations
• Responsiveness
🧾
Types of CSS
🔤
CSS Syntax & Selectors
Basic Syntax:
selector {
property: value;
}
Common Selectors:
1. Inline CSS
2. Internal CSS
<!DOCTYPE html>
<html>
<head>
<style>
p {
color: blue;
font-size: 20px;
}
</style>
</head>
<body>
<p>This is internal CSS</p>
</body>
</html>
3. External CSS
HTML File:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<p class="text">This is external CSS</p>
</body>
</html>
style.css:
.text {
color: purple;
font-weight: bold;
}
🎨 Styling a button
button {
background-color: teal;
color: white;
border: none;
padding: 10px 15px;
border-radius: 5px;
cursor: pointer;
}
🧱
Center an element
.center {
margin: 0 auto;
width: 50%;
text-align: center;
}
🧩
Mini Project: "Personal Profile Card"
👇
Requirements:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">
<title>Profile Card</title>
</head>
<body>
<div class="card">
<img src="profile.jpg" alt="Profile Picture" class="profile-img">
<h2>Waseem Adil</h2>
<p>Web Developer | Learner | Creator</p>
</div>
</body>
</html>
🎨 CSS (style.css)
body {
font-family: Arial, sans-serif;
background-color: #f0f0f0;
text-align: center;
padding-top: 50px;
}
.card {
background-color: white;
padding: 20px;
width: 300px;
margin: auto;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
.profile-img {
width: 100px;
border-radius: 50%;
margin-bottom: 10px;
}
🎨
Colors in CSS
Example:
color: red;
background-color: lightblue;
✅
HEX Code:
✅ HSL:
📝 Text Styling
Property Description Example
🧾
Example:
h1 {
font-family: "Georgia", serif;
font-size: 32px;
font-weight: bold;
font-style: italic;
text-align: center;
}
🖼
Backgrounds
Property Description Example
background-image:
background-image Sets image as background
url("bg.jpg");
background-
Position of image background-position: center;
position
Example:
body {
background-color: #fafafa;
background-image: url("pattern.png");
background-repeat: no-repeat;
background-position: top right;
background-size: 100px;
}
Part Description
Visual Representation:
+-----------------------------+
| margin |
| +----------------------+ |
| | border | |
| | +---------------+ | |
| | | padding | | |
| | | +--------+ | | |
| | | | content| | | |
| | | +--------+ | | |
| | +---------------+ | |
| +----------------------+ |
+-----------------------------+
Example:
.box {
border: 2px solid #333;
padding: 20px;
margin: 40px;
}
📏
CSS Units
Unit Description Example
📝 Goal:
Create a beautiful, responsive quote card using basic CSS properties learned in this lesson.
✅
HTML:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css" />
<title>Quote Card</title>
</head>
<body>
<div class="quote-card">
<p class="quote">
"The only way to do great work is to love what you do."
</p>
<p class="author">- Steve Jobs</p>
</div>
</body>
</html>
🎨
CSS (style.css):
body {
background-color: #e0f7fa;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
font-family: "Helvetica", sans-serif;
}
.quote-card {
background-color: #ffffff;
padding: 30px;
border: 2px solid #00838f;
border-radius: 15px;
width: 80%;
max-width: 500px;
text-align: center;
box-shadow: 0 0 15px rgba(0, 0, 0, 0.2);
}
.quote {
font-size: 1.5rem;
font-style: italic;
color: #006064;
margin-bottom: 15px;
}
.author {
font-weight: bold;
color: #004d40;
}
📘
Box Model
The CSS Box Model describes how elements are displayed and spaced on a webpage.
+-----------------------------+
| Margin |
| +----------------------+ |
| | Border | |
| | +---------------+ | |
| | | Padding | | |
| | | +--------+ | | |
| | | | Content| | | |
| | | +--------+ | | |
| | +---------------+ | |
| +----------------------+ |
+-----------------------------+
✅
CSS Example:
.box {
width: 200px;
height: 100px;
padding: 20px;
border: 2px solid #333;
margin: 30px;
background-color: #f2f2f2;
}
🧱 Display Property
Value Behavior
✅
Example:
.block {
display: block;
}
.inline {
display: inline;
}
.inline-block {
display: inline-block;
width: 100px;
height: 50px;
}
📐
Width & Height
Defines the size of the content box (excluding padding, border, margin).
div {
width: 300px;
height: 150px;
}💡
Behavior
Value
✅ Example:
.scroll-box {
width: 300px;
height: 100px;
overflow: auto;
}
📏
min-height / max-width
.responsive-box {
max-width: 600px;
min-height: 200px;
width: 100%;
}
✅
Useful for responsive layouts – allows flexible size but prevents too small or too large elements.
🧩
Mini Project: "Responsive Info Card with Box Model"
✅
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Info Card</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div class="card">
<h2>Welcome to CSS Layout</h2>
<p>
This box demonstrates the box model, layout behaviors, and
responsiveness using max-width and min-height.
</p>
</div>
</body>
</html>
🎨 CSS (style.css):
body {
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
background: #e0f7fa;
margin: 0;
font-family: sans-serif;
}
.card {
max-width: 500px;
min-height: 200px;
padding: 20px;
border: 3px solid #00838f;
background-color: white;
margin: 40px;
overflow: auto;
display: block;
text-align: center;
box-shadow: 0 0 15px rgba(0, 0, 0, 0.1);
}
Q1. What part of the box model contains the actual content of the element?
A) Padding
B) Border
C) Content
D) Margin
Q2. Which display property value allows setting width and height on an inline element?
A) block
B) inline
C) inline-block
D) none
A) scroll
B) auto
C) hidden
D) visible
A) em
B) vh
C) vw
D) rem
Q6. Which CSS property is used to prevent content from spilling out of a container?
A) display
B) overflow
C) max-height
D) padding
A) It becomes transparent
B) It becomes unclickable
C) It is removed from the document layout
D) It is hidden but still occupies space
Q8. What does max-width do?
Q9. If a div has padding: 10px; border: 5px solid black; margin: 20px; and
width: 200px;, what is the total width of the element?
A) 200px
B) 230px
C) 250px
D) 270px
A) inline
B) block
C) inline-block
D) none
✅
Answer Key
✅
1. ✅ C) Content
2. ✅ C) inline-block
3. ✅ D) visible
4. ✅ C) vw
5. ✅ B) Adds space around the border
6.
✅ B) overflow
7.
✅ C) It is removed from the document layout
✅
8. C) Sets the largest width an element can be
✅
9. D) 270px → (200 + 10+10 + 5+5 + 20+20)
10. D) none