01-Introduction (1)
01-Introduction (1)
3. The syntax and structure of CSS, including selectors, properties, and values.
01-Introduction 1
1. What is CSS?
Definition:
CSS stands for Cascading Style Sheets, and it is used to control the style and
layout of HTML elements. While HTML provides the structure of a webpage, CSS
gives it life by defining how elements should look and behave.
In simpler terms:
CSS = Style + Layout.
CSS: Styles and arranges those structures (e.g., colors, fonts, spacing).
Importance of CSS:
Separation of Concerns: CSS separates content (HTML) from presentation
(CSS). This helps in maintaining and updating the website's look without
changing its structure.
01-Introduction 2
Improves Readability: CSS makes your website look more appealing and easy
to navigate, which directly impacts user experience.
Real-World Analogy:
Think of HTML as the frame of a house (the skeleton), and CSS is the interior
design (colors, furniture, style). The frame stays the same, but the interior can be
adjusted to look stylish and organized!
Inline CSS:
01-Introduction 3
Inline CSS is written directly inside HTML tags using the style attribute.
Advantages:
Disadvantages:
Internal CSS:
Internal CSS is written within the <style> tag in the head section of the HTML
document.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Internal CSS Example</title>
<style>
p{
color: green;
font-size: 18px;
}
</style>
</head>
<body>
<p>This is a styled paragraph using internal CSS.</p>
</body>
</html>
Advantages:
01-Introduction 4
Keeps styles together in one document.
Disadvantages:
External CSS:
External CSS is the most efficient method, especially for large websites. You
create a separate .css file and link it to the HTML.
HTML File:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>External CSS Example</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<p>This is a styled paragraph using external CSS.</p>
</body>
</html>
p{
color: red;
font-size: 22px;
}
Advantages:
Centralized styling: One .css file can be linked to multiple HTML pages.
01-Introduction 5
Makes large websites easier to maintain.
Disadvantages:
2. Property: Defines the style you want to apply (e.g., color, font-size).
01-Introduction 6
selector {
property: value;
}
For example:
p{
color: blue;
font-size: 18px;
}
01-Introduction 7
Property: color (specifies the color)
h1 {
color: blue;
}
.myClass {
background-color: yellow;
}
#myID {
font-size: 24px;
}
*{
margin: 0;
padding: 0;
}
div p {
color: red;
}
01-Introduction 8
6. Pseudo-classes: Targets elements in a specific state, like hover.
a:hover {
color: orange;
}
font-size : Sets the size of the text (e.g., 16px , 1em , 1.5rem ).
01-Introduction 9
4. Colors and Backgrounds
Color Formats:
1. Named Colors: CSS supports common color names like red , green , blue , etc.
3. RGB Colors: Defines colors using the Red, Green, and Blue channels (e.g.,
rgb(255, 0, 0) ).
01-Introduction 10
4. HSL Colors: Defines colors based on Hue, Saturation, and Lightness (e.g.,
hsl(0, 100%, 50%) ).
Background Properties:
1. background-color : Sets the background color of an element.
body {
background-color: lightblue;
}
body {
background-image: url('image.jpg');
}
body {
background-position: center center;
}
body {
background-repeat: no-repeat;
}
Font Properties:
01-Introduction 11
1. font-family : Specifies the font of an element (e.g., Arial , Verdana ).
Text Styling:
1. line-height : Controls the space between lines of text.
3. text-align : Aligns the text inside an element (e.g., left , center , right ).
01-Introduction 12