This article teaches you how to play with CSS combination selectors

This article teaches you how to play with CSS combination selectors

CSS combination selectors include various combinations of simple selectors.

There are four combinations in CSS3:

  • Descendant selectors (space separated)
  • Child element selector (separated by greater than sign)
  • Adjacent sibling selectors (separated by plus signs)
  • Normal sibling selectors (dash-separated)

1. Descendant Selector

The descendant selector is used to select descendant elements of an element.

The following example selects all <p> elements and inserts them into a <div> element:

div p{
      background-color:yellow;
    }

2. Child element selector

Compared to descendant selectors, child selectors can only select elements that are children of another element.

The following example selects all <p> elements that are direct children of a <div> element:

 div>p {
      background-color:yellow;
    }

3. Adjacent sibling selector

The adjacent sibling selector selects an element that is immediately after another element and has the same parent.

If you need to select an element that is immediately after another element and both have the same parent, you can use the adjacent sibling selector.

The following example selects all <p> elements that are located after the first <div> element:

div+p{
      background-color:yellow;
    }

4. Subsequent sibling selector

The following sibling selector selects all the adjacent sibling elements following the specified element.

The following example selects all adjacent sibling elements <p> after all <div> elements:

div~p {
      background-color:yellow;
    }

This is the end of this article about teaching you how to use CSS combination selectors. For more relevant CSS combination selector content, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope you will support 123WORDPRESS.COM in the future!

<<:  Some understanding of absolute and relative positioning of page elements

>>:  Two ways to start Linux boot service

Recommend

How to use cc.follow for camera tracking in CocosCreator

Cocos Creator version: 2.3.4 Demo download: https...

Solve the problem of docker pull image error

describe: Install VM under Windows 10, run Docker...

How to configure SSL for koa2 service

I. Introduction 1: SSL Certificate My domain name...

CSS3 achieves cool 3D rotation perspective effect

CSS3 achieves cool 3D rotation perspective 3D ani...

Solution to garbled display of Linux SecureCRT

Let's take a look at the situation where Secu...

Summary of Linux sftp command usage

sftp is the abbreviation of Secure File Transfer ...

Detailed process of decompressing and installing mysql5.7.17 zip

1. Download address https://dev.mysql.com/downloa...

JavaScript implements the detailed process of stack structure

Table of contents 1. Understanding the stack stru...

A record of a Linux server intrusion emergency response (summary)

Recently, we received a request for help from a c...

An article to help you understand the basics of VUE

Table of contents What is VUE Core plugins in Vue...

The textarea tag cannot be resized and cannot be dragged with the mouse

The textarea tag size is immutable Copy code The c...

Solution for front-end browser font size less than 12px

Preface When I was working on a project recently,...