Home Web Front-end CSS Tutorial Detailed analysis of CSS style inheritance and cascading

Detailed analysis of CSS style inheritance and cascading

Apr 24, 2017 am 09:24 AM

This article mainly introduces CSS style Inheritance and cascading related information. Friends in need can refer to

1:Basic selector

Tag selection: Select according to the tag name on the page, and directly apply the style to the specified tag.

Features:

1. Tag selector will select all specified tags in the current page;

2 The .tag selector has no relation to the current tag hierarchy of the code and can be selected as long as it is on the current page.

ID selection: You need to specify a tag to set the id value first (the id value cannot be repeated and is unique in the entire page).

classSelection: Give the label a class name and select the specified label through the class selector.

Two: Three sets of complex selectors

1.Descendant selectors

A. You can find subsequent sub-tags based on the tags in the current selection

B. The descendant selector can perform multi-layer precise selection

2.Intersection selector

Format: Select the first layer and select the second layer {}

Note: Points represent intersections, usually starting with a label

3. Union selection Selector

Format: first selector, second selector,...{}

Three:css inheritance property

Definition: There are some styles. When setting the current tag, it will also set its descendant tags.
Note: Tags that inherit the style and tags that define the style must It is a subordinate relationship (descendant tag relationship)
Basic attributes for text style settings can be inherited (color color\style text\font font\line attribute line)
All about the box model ( p, span, etc.) property settings (border, positioning, layout) cannot be inherited

Four: css cascading

Definition: When multiple selectors act on the same tag at the same time, the style will be applied according to priority

Selector judgment method:

-Through the weight judgment method
-Calculate the weight (ICE) through the number of id selections, class selections, and label selections in each selection
-Compare the id weights first, and then compare the categories, The last comparison tag is
- all the same comparison order

Note: If the weights are the same, the later ones will overwrite the previous ones. The premise of numerical weight is to ensure that each selector must select the specified element.

If the scope does not directly affect the label itself, it reflects the proximity principle.

important has the highest priority, * has the lowest priority

The above is the detailed content of Detailed analysis of CSS style inheritance and cascading. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

Repo: How To Revive Teammates
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Detailed explanation of C++ function inheritance: How to use 'base class pointer' and 'derived class pointer' in inheritance? Detailed explanation of C++ function inheritance: How to use 'base class pointer' and 'derived class pointer' in inheritance? May 01, 2024 pm 10:27 PM

In function inheritance, use "base class pointer" and "derived class pointer" to understand the inheritance mechanism: when the base class pointer points to the derived class object, upward transformation is performed and only the base class members are accessed. When a derived class pointer points to a base class object, a downward cast is performed (unsafe) and must be used with caution.

How do inheritance and polymorphism affect class coupling in C++? How do inheritance and polymorphism affect class coupling in C++? Jun 05, 2024 pm 02:33 PM

Inheritance and polymorphism affect the coupling of classes: Inheritance increases coupling because the derived class depends on the base class. Polymorphism reduces coupling because objects can respond to messages in a consistent manner through virtual functions and base class pointers. Best practices include using inheritance sparingly, defining public interfaces, avoiding adding data members to base classes, and decoupling classes through dependency injection. A practical example showing how to use polymorphism and dependency injection to reduce coupling in a bank account application.

How to create a slideshow layout page using HTML and CSS How to create a slideshow layout page using HTML and CSS Oct 16, 2023 am 09:07 AM

How to create a slide layout page using HTML and CSS Introduction: Slide layout is widely used in modern web design and is very attractive and interactive when displaying information or pictures. This article will introduce how to create a slide layout page using HTML and CSS, and provide specific code examples. 1. HTML layout structure First, we need to create an HTML layout structure, including a slide container and multiple slide items. The code looks like this: <!DOCTYPEhtml&

Detailed explanation of C++ function inheritance: How to debug errors in inheritance? Detailed explanation of C++ function inheritance: How to debug errors in inheritance? May 02, 2024 am 09:54 AM

Inheritance error debugging tips: Ensure correct inheritance relationships. Use the debugger to step through the code and examine variable values. Make sure to use the virtual modifier correctly. Examine the inheritance diamond problem caused by hidden inheritance. Check for unimplemented pure virtual functions in abstract classes.

Packaging technology and application in PHP Packaging technology and application in PHP Oct 12, 2023 pm 01:43 PM

Encapsulation technology and application encapsulation in PHP is an important concept in object-oriented programming. It refers to encapsulating data and operations on data together in order to provide a unified access interface to external programs. In PHP, encapsulation can be achieved through access control modifiers and class definitions. This article will introduce encapsulation technology in PHP and its application scenarios, and provide some specific code examples. 1. Encapsulated access control modifiers In PHP, encapsulation is mainly achieved through access control modifiers. PHP provides three access control modifiers,

How to use:nth-child(-n+5) pseudo-class selector to select the CSS style of child elements whose position is less than or equal to 5 How to use:nth-child(-n+5) pseudo-class selector to select the CSS style of child elements whose position is less than or equal to 5 Nov 20, 2023 am 11:52 AM

How to use:nth-child(-n+5) pseudo-class selector to select the CSS style of child elements whose position is less than or equal to 5. In CSS, the pseudo-class selector is a powerful tool that can be selected through a specific selection method. Certain elements in an HTML document. Among them, :nth-child() is a commonly used pseudo-class selector that can select child elements at specific positions. :nth-child(n) can match the nth child element in HTML, and :nth-child(-n) can match

C++ function inheritance explained: When should inheritance not be used? C++ function inheritance explained: When should inheritance not be used? May 04, 2024 pm 12:18 PM

C++ function inheritance should not be used in the following situations: When a derived class requires a different implementation, a new function with a different implementation should be created. When a derived class does not require a function, it should be declared as an empty class or use private, unimplemented base class member functions to disable function inheritance. When functions do not require inheritance, other mechanisms (such as templates) should be used to achieve code reuse.

How to implement a simple chat page layout using HTML and CSS How to implement a simple chat page layout using HTML and CSS Oct 18, 2023 am 08:42 AM

How to use HTML and CSS to implement a simple chat page layout With the development of modern technology, people increasingly rely on the Internet for communication and communication. In web pages, chat pages are a very common layout requirement. This article will introduce you to how to use HTML and CSS to implement a simple chat page layout, and give specific code examples. First, we need to create an HTML file, you can use any text editor. Taking index.html as an example, first create a basic HTML

See all articles