- Смежные селекторы
- Синтаксис
- Пример
- Спецификации
- Поддержка браузерами
- Смотрите также
- Found a content problem with this page?
- MDN
- Support
- Our communities
- Developers
- CSS Combinators
- Descendant Selector
- Example
- Child Selector (>)
- Example
- Adjacent Sibling Selector (+)
- Example
- General Sibling Selector (~)
- Combinators
- Descendant combinator
- Child combinator
- Test your skills!
- Summary
- Found a content problem with this page?
- CSS adjacent sibling selectors
Смежные селекторы
Указывает на смежный или следующий селектор. Обеспечивает выбор только элемента расположенного непосредственно за определённым в первой части элементом.
Синтаксис
former_element + target_element
Пример
li:first-of-type + li color: red; >
ul> li>Одинli> li>Дваli> li>Триli> ul>
Так же может использоваться для задания стиля определённого класса «caption span» следующих вложенных элементов:
img + span.caption font-style: italic; >
сработает только на тех тегах span, для которых задан класс caption:
img src="photo1.jpg">span class="caption">Первая фоткаspan> img src="photo2.jpg">span class="caption">Втораяspan>
Спецификации
Поддержка браузерами
BCD tables only load in the browser
Смотрите также
Found a content problem with this page?
This page was last modified on 7 нояб. 2022 г. by MDN contributors.
Your blueprint for a better internet.
MDN
Support
Our communities
Developers
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998– 2023 by individual mozilla.org contributors. Content available under a Creative Commons license.
CSS Combinators
A combinator is something that explains the relationship between the selectors.
A CSS selector can contain more than one simple selector. Between the simple selectors, we can include a combinator.
There are four different combinators in CSS:
- descendant selector (space)
- child selector (>)
- adjacent sibling selector (+)
- general sibling selector (~)
Descendant Selector
The descendant selector matches all elements that are descendants of a specified element.
The following example selects all
elements inside elements:
Example
Child Selector (>)
The child selector selects all elements that are the children of a specified element.
The following example selects all
elements that are children of a element:
Example
Adjacent Sibling Selector (+)
The adjacent sibling selector is used to select an element that is directly after another specific element.
Sibling elements must have the same parent element, and «adjacent» means «immediately following».
The following example selects the first
element that are placed immediately after elements:
Example
General Sibling Selector (~)
The general sibling selector selects all elements that are next siblings of a specified element.
The following example selects all
elements that are next siblings of elements:
Combinators
The final selectors we will look at are called combinators, because they combine other selectors in a way that gives them a useful relationship to each other and the location of content in the document.
Prerequisites: | Basic computer literacy, basic software installed, basic knowledge of working with files, HTML basics (study Introduction to HTML), and an idea of how CSS works (study CSS first steps.) |
---|---|
Objective: | To learn about the different combinator selectors that can be used in CSS. |
Descendant combinator
The descendant combinator — typically represented by a single space (» «) character — combines two selectors such that elements matched by the second selector are selected if they have an ancestor (parent, parent’s parent, parent’s parent’s parent, etc.) element matching the first selector. Selectors that utilize a descendant combinator are called descendant selectors.