Lec-10 W5 - (CSS-Selectors Part 2)
Lec-10 W5 - (CSS-Selectors Part 2)
WEB DEVELOPMENT
Lecturer – W5
Lecture Outline
CSS Selectors
The Descendant Selector
The Child Selector
Adjacent selector
Sibling Selector
Attribute selector
Pseudo-classes
Pseudo-Elements
1
4/24/2024
2
4/24/2024
3
4/24/2024
<!DOCTYPE html>
<html>
<head> <style>
div + p {background-color: yellow;}
</style> </head>
<body>
<div>
<p>Paragraph 1. in the div</p>
</div>
<p>Paragraph 2. Not in a div</p>
<p>Paragraph 3. Not in a div</p>
</body>
</html>
10
4
4/24/2024
11
<!DOCTYPE html>
<html>
<head>
<style>
div ~ p { background-color: yellow;}
</style>
</head>
<body>
<div>
<p>Paragraph 1, child of the div.</p>
</div>
<p>Paragraph 2, sibling of the div.</p>
<p>Paragraph 3, sibling of the div.</p>
</body>
</html>
12
5
4/24/2024
13
14
6
4/24/2024
15
16
7
4/24/2024
CSS Pseudo-elements
What are Pseudo-Elements?
A CSS pseudo-element is used to style specified parts of an
element.
For example, it can be used to:
Style the first letter, or line, of an element
Insert content before, or after, the content of an element
The syntax of pseudo-elements:
selector::pseudo-element { property: value; }
p::first-line {
color: #ff0000;
font-variant: small-caps;
}
17
18
8
4/24/2024
Example……CSS Pseudo-elements
<!DOCTYPE html>
<html>
<head> <style>
h3::after {content: "Remember this";}
h3::first-letter {font-size: 200%; color: #8A2BE2;}
p::first-line {background-color: yellow; }
::marker {color: red; font-size: 23px;}
::selection {color: red; background: yellow;}
</style></head>
<body>
<h1>Demo of the CSS Pseudo Elements</h1>
<h3>Your time is limited, so don't waste it living
someone else's life. Don't be trapped by dogma —
which is living with the results of other people's
thinking.....</h3>
<p>“Self forgiveness is one of the most unselfish
things you can do. Everyone around benefits as
you become less demanding, more giving, and more
forgiving."</p>
<ol>
<li>Item 1</li> <li>Item 2</li> <li>Item 3</li>
</ol>
</body></html>
19