Pseudo-elements and Pseudo-classes Flashcards

1
Q

Hover Effect

button:hover {
  background: blue;
  color: white;
}
<button>Hover Me</button>
A

Button turns blue when hovered.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Style Every Other Row

tr:nth-child(odd) {
  background: lightgray;
}
<table>
  <tr><td>Row 1</td></tr>
  <tr><td>Row 2</td></tr>
  <tr><td>Row 3</td></tr>
</table>
A

Odd rows get a gray background.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Style Only Checked Checkboxes

input:checked {
  accent-color: green;
}
<input type="checkbox" checked> Checked
<input type="checkbox"> Not Checked
A

Checked checkboxes turn green.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Exclude Certain Elements

p:not(.special) {
  color: gray;
}
<p>This is normal.</p>
<p class="special">This is special.</p>
A

Only normal <p> elements turn gray.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

First Letter Styling

p::first-letter {
  font-size: 2em;
  color: red;
}
<p>This is a paragraph.</p>
A

The first letter of the paragraph is bigger and red.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Inserting Content Before and After

h1::before {
  content: "πŸ”₯ ";
}

h1::after {
  content: " ⭐";
}
<h1>My Heading</h1>
A

Displays as πŸ”₯ My Heading ⭐.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Styling Selected Text

p::selection {
  background: yellow;
  color: black;
}
<p>Try selecting this text!</p>
A

Selected text highlights in yellow.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Change First Letter Only When Hovered

p:hover::first-letter {
  color: blue;
  font-size: 2em;
}
<p>Hover over this text.</p>
A

The first letter turns blue only when hovered.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Style the First Letter of First Child Paragraph

p:first-child::first-letter {
  font-size: 2em;
  color: red;
}
<div>
  <p>First paragraph.</p>
  <p>Second paragraph.</p>
</div>
A

Only the first letter of the first <p> is red.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Add β€œπŸ”—β€ Before External Links

a[href^="http"]:not([href*="mywebsite.com"])::before {
  content: "πŸ”— ";
  color: red;
}
<a href="https://google.com">Google</a>
<a href="https://mywebsite.com">My Website</a>
A

External links get a πŸ”— icon, but internal links don’t.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is Pseudo-Element

A

(::)
Pseudo-elements allow you to style a specific part of an element, such as the first letter or inserting content.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is Pseudo-Classess?

A

(:)
Pseudo-classes act like β€œtemporary classes” applied under specific conditions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Here are some examples of pseudo-classes:

A

:nth-child(n)
Targets an element based on position among siblings tr:nth-child(odd) { background: lightgray; }
:first-child
Targets the first child of a parent p:first-child { font-weight: bold; }
:last-child
Targets the last child of a parent li:last-child { color: red; }
:not(selector)
Excludes certain elements p:not(.special) { color: gray; }

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Here are some examples of psuedo-elements:

A

::first-letter
Styles the first letter of an element p::first-letter { font-size: 2em; }
::first-line
Styles the first line of an element p::first-line { font-weight: bold; }
::before
Inserts content before an element h1::before { content: "πŸ”₯ "; }
::after
Inserts content after an element h1::after { content: " ⭐"; }
::selection
Styles the text when selected p::selection { background: yellow; color: black; }

How well did you know this?
1
Not at all
2
3
4
5
Perfectly