![]() |
Combinators: When classes are combined, they become more specific. This allows you to target classes further down in your template without affecting other elements. Selectors can be combined into a combinator: Combinator of Descendent, Child, Sibling, and General Sibling. The Descendent Combinator is the most well-known and widely used. Descendant: A (parent) element and an element in a (few) more nested levels are combined in a single selector. The nested level selector does not have to be a child element of the parent selector’s target element. Through ‘unique’ landmarks within your template, you can skip levels of explicit selectors to get to your target selector. Child: The child selection returns all elements that are children of a given element. Adjacent sibling: The CSS adjacent sibling selector is used to find an element’s adjacent sibling. It is used to pick only elements that come shortly after the first selector. General sibling: The tilde (~) sign is used as a separator between the elements. It chooses the elements that come after the elements of the first selector, and they are both children of the same parent. It can be used to select a group of elements that all have the same parent element. In this article, we are going to use adjacent sibling combinators to get the next element of CSS. Syntax: .parent-class + .sibling-class Example 1: In this example, we’re using the adjacent sibling combinator give me the font size and color of paragraph text. </p> tag follow the </div> to get value.
Output: Example 2: In this example, we’re using the adjacent sibling combinator to move the button element next to the description element in each card. The first three rules style the different elements of the card, while the last rule selects the .cardButton element that immediately follows the .cardDescription element, and applies some CSS properties to move the button to the right of the description.
Output: |
Reffered: https://www.geeksforgeeks.org
CSS |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 12 |