前面的话
层叠样式表中最基本的一方面是层叠——冲突的声明通过层叠过程排序,并由此确定最终的文档表示,这个过程的核心是选择器及其相关声明的特殊性,以及继承机制。
特殊性
选择器的特殊性由选择器本身的组件确定。特殊性值表述为4个部分:
【1】内联样式 -> 1,0,0,0
【2】ID属性值 -> 0,1,0,0
【3】类属性值、属性选择或伪类 -> 0,0,1,0
【4】元素或伪元素 -> 0,0,0,1
【5】结合符和通配选择器 -> 0,0,0,0
h1{} -> 0,0,0,1p em{} -> 0,0,0,2.grape{} -> 0,0,1,0*.bright{} -> 0,0,1,0p.bright em.dark{} -> 0,0,2,2#id121{} -> 0,1,0,0div#side *[href]{} -> 0,1,1,1
重要性
重要声明:在声明的结束分号之前插入!important来标志
继承
继承是从一个元素向其后代元素传递属性值所采用的机制。基于继承机制,样式不仅可以应用到指定的元素,还会应用到它的后代元素。继承的属性没有特殊性。
[注意1]在HTML中,应用到body元素的背景样式可以传递到html元素
[注意2]标签不会继承父元素的文本样式
层叠
【1】按来源及重要性排序。读者!important > 创作人员!important > 创作人员 > 读者 > 用户代理
【2】按特殊性排序
【3】按出现顺序排序,一个声明在样式表或文档中越后出现,权重越大

The article explains that HTML tags are syntax markers used to define elements, while elements are complete units including tags and content. They work together to structure webpages.Character count: 159

The article discusses the roles of <head> and <body> tags in HTML, their impact on user experience, and SEO implications. Proper structuring enhances website functionality and search engine optimization.

The article discusses the differences between HTML tags , , , and , focusing on their semantic vs. presentational uses and their impact on SEO and accessibility.

Article discusses specifying character encoding in HTML, focusing on UTF-8. Main issue: ensuring correct display of text, preventing garbled characters, and enhancing SEO and accessibility.

The article discusses various HTML formatting tags used for structuring and styling web content, emphasizing their effects on text appearance and the importance of semantic tags for accessibility and SEO.

The article discusses the differences between HTML's 'id' and 'class' attributes, focusing on their uniqueness, purpose, CSS syntax, and specificity. It explains how their use impacts webpage styling and functionality, and provides best practices for

The article explains the HTML 'class' attribute's role in grouping elements for styling and JavaScript manipulation, contrasting it with the unique 'id' attribute.

Article discusses HTML list types: ordered (<ol>), unordered (<ul>), and description (<dl>). Focuses on creating and styling lists to enhance website design.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

Notepad++7.3.1
Easy-to-use and free code editor

Dreamweaver Mac version
Visual web development tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.
