Skip to content

Commit 7080c05

Browse files
Create Selectors.md
1 parent 1eb223d commit 7080c05

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

docs/CSS/css-basics/Selectors.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# CSS Selectors
2+
3+
CSS selectors are patterns used to select and style HTML elements. Selectors target specific elements based on their type, class, ID, attributes, or position in the document. Here are some common types of CSS selectors:
4+
5+
## 1. Element Selector
6+
7+
Selects HTML elements based on their element type.
8+
9+
Example:
10+
```css
11+
p {
12+
color: blue;
13+
}
14+
```
15+
This will select all `<p>` elements and make their text blue.
16+
## 2. Class Selector
17+
18+
Selects elements with a specific class attribute.
19+
20+
Example:
21+
```css
22+
.my-class {
23+
font-weight: bold;
24+
}
25+
```
26+
This will select all elements with `class="my-class"` and make their text bold.
27+
## 3. ID Selector
28+
29+
Selects a single element with a specific ID attribute.
30+
31+
Example:
32+
```css
33+
#my-id {
34+
background-color: yellow;
35+
}
36+
```
37+
This will select the element with `id="my-id"` and give it a yellow background.
38+
39+
## 4. Attribute Selector
40+
41+
Selects elements based on their attribute values.
42+
43+
Example:
44+
45+
```css
46+
input[type="text"] {
47+
border: 1px solid #ccc;
48+
}
49+
```
50+
This will select all `<input>` elements with `type="text"` and give them a 1px solid border with color #ccc.
51+
52+
## 5. Pseudo-Classes
53+
54+
Selects elements based on their state or position.
55+
56+
Example:
57+
```css
58+
a:hover {
59+
color: red;
60+
}
61+
```
62+
This will select all `<a>` elements when hovered over and make their text red.
63+
64+
## 6. Pseudo-elements
65+
66+
Selects and styles a part of an element.
67+
Example:
68+
69+
```css
70+
71+
p::first-line {
72+
font-weight: bold;
73+
}
74+
```
75+
This will select and make the first line of all `<p>` elements bold.

0 commit comments

Comments
 (0)