/
index.md
67 lines (48 loc) · 1.11 KB
/
index.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
---
title: ":only-of-type"
slug: Web/CSS/:only-of-type
page-type: css-pseudo-class
browser-compat: css.selectors.only-of-type
---
{{CSSRef}}
The **`:only-of-type`** CSS [pseudo-class](/en-US/docs/Web/CSS/Pseudo-classes) represents an element that has no siblings of the same type.
{{EmbedInteractiveExample("pages/tabbed/pseudo-class-only-of-type.html", "tabbed-shorter")}}
## Syntax
```css
:only-of-type {
/* ... */
}
```
## Examples
### Styling elements with no siblings of the same type
#### HTML
```html
<main>
<div>I am `div` #1.</div>
<p>I am the only `p` among my siblings.</p>
<div>I am `div` #2.</div>
<div>
I am `div` #3.
<i>I am the only `i` child.</i>
<em>I am `em` #1.</em>
<em>I am `em` #2.</em>
</div>
</main>
```
#### CSS
```css
main :only-of-type {
color: red;
}
```
#### Result
{{EmbedLiveSample('Styling_elements_with_no_siblings_of_the_same_type','100%',180)}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{Cssxref(":only-child")}}
- {{Cssxref(":first-of-type")}}
- {{Cssxref(":last-of-type")}}
- {{Cssxref(":nth-of-type")}}