:only-of-type
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
CSS псевдокласс :only-of-type
выбирает элемент, который является единственным потомком своего типа.
Интерактивный пример
Синтаксис
css
:only-of-type {
/* ... */
}
Примеры
Применение стилей к элементам, которые являются единственными потомками своего типа
HTML
html
<main>
<div>Я элемент `div` #1.</div>
<p>Я единственный элемент `p` у своего родителя.</p>
<div>Я элемент `div` #2.</div>
<div>
Я элемент `div` #3.
<i>Я единственный элемент `i` у своего родителя.</i>
<em>Я элемент `em` #1.</em>
<em>Я элемент `em` #2.</em>
</div>
</main>
CSS
css
main :only-of-type {
color: red;
}
Результат
Спецификации
Specification |
---|
Selectors Level 4 # only-of-type-pseudo |
Совместимость с браузерами
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
:only-of-type |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- See implementation notes.
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.