Table of Contents
前面的话
initial
inherit
unset
revert
all
Home Web Front-end HTML Tutorial initial、inherit、unset、revert和all_html/css_WEB-ITnose

initial、inherit、unset、revert和all_html/css_WEB-ITnose

Jun 24, 2016 am 11:18 AM

× 目录 [1]initial [2]inherit [3]unset [4]revert [5]all

前面的话

  在CSS中,有4个关键字理论上可以应用于任何的CSS属性,它们是initial(初始)、inherit(继承)、unset(未设置)、revert(还原)。而all的取值只能是以上这4个关键字。本文将介绍initial、inherit、unset、revert和all

 

initial

  表示元素属性的初始默认值(该默认值由官方CSS规范定义)

  兼容性: IE不支持

  [注意]关于各属性的初始默认值移步至此

//display在官方CSS规范中定义的默认值是inline<style>.test{display: initial;}</style><div class="box">    <div class="test">测试一</div><span>文字</span>    <br>    <div >测试二</div><span>文字</span></div>
Copy after login

inherit

  表示元素的直接父元素对应属性的计算值

  兼容性: IE7-不支持

<style>.box{    border: 1px solid black;    padding: 10px;    width: 100px;}.test{    border: inherit;    height: 30px;}</style><div class="box">    <div class="test">测试一</div></div><div class="box">    <div class="in">        <div class="test">测试二</div>            </div></div>
Copy after login

unset

  unset相对于initial和inherit而言,相对复杂一点。表示如果该属性默认可继承,则值为inherit;否则值为initial。实际上,设置unset相当于不设置

  兼容性: IE不支持,safari9-不支持,ios9.2-不支持,android4.4.4-不支持

【常用默认可继承样式】

colorcursordirectionfontletter-spacingline-heightlist-styletext-aligntext-indenttext-shadowtext-transformwhite-spaceword-breakword-spacingword-wrapwriting-mode
Copy after login

//内容为测试一的元素和内容为测试二的元素的样式是一样的<style>.box{    border: 1px solid black;    padding: 10px;    width: 100px;    color: red;}.test1{    border: unset;    color: unset;}</style><div class="box">    <div class="test">测试一</div>    <div>测试二</div></div>
Copy after login

revert

  表示样式表中定义的元素属性的默认值。若用户定义样式表中显式设置,则按此设置;否则,按照浏览器定义样式表中的样式设置;否则,等价于unset

  兼容性: 只有safari9.1+和ios9.3+支持

all

  表示重设除unicode-bidi和direction之外的所有CSS属性的属性值,取值只能是initial、inherit、unset和revert

  兼容性: IE不支持,safari9-不支持,ios9.2-不支持,android4.4-不支持

<style>.test{    border: 1px solid black;    padding: 20px;    color: red;}.in{/*  all: initial;    all: inherit;    all: unset;    all: revert; */}</style><div class="test">    <div class="in">测试文字</div>            </div>
Copy after login

  【1】当all:initial时,.in的所有属性都取默认值

border:none;padding:0;color:black;
Copy after login

  【2】当all:inherit时,.in的所有属性都取父元素继承值

border:1px solid black;padding:20px;color:red;
Copy after login

  【3】当all:unset时,.in的所有属性都相当于不设置值,默认可继承的继承,不可继承的保持默认值

border:none;padding:0;color:red;
Copy after login

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 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)

What is the purpose of the <progress> element? What is the purpose of the <progress> element? Mar 21, 2025 pm 12:34 PM

The article discusses the HTML &lt;progress&gt; element, its purpose, styling, and differences from the &lt;meter&gt; element. The main focus is on using &lt;progress&gt; for task completion and &lt;meter&gt; for stati

Is HTML easy to learn for beginners? Is HTML easy to learn for beginners? Apr 07, 2025 am 12:11 AM

HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.

What is the purpose of the <datalist> element? What is the purpose of the <datalist> element? Mar 21, 2025 pm 12:33 PM

The article discusses the HTML &lt;datalist&gt; element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

What is the purpose of the <meter> element? What is the purpose of the <meter> element? Mar 21, 2025 pm 12:35 PM

The article discusses the HTML &lt;meter&gt; element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates &lt;meter&gt; from &lt;progress&gt; and ex

What is the viewport meta tag? Why is it important for responsive design? What is the viewport meta tag? Why is it important for responsive design? Mar 20, 2025 pm 05:56 PM

The article discusses the viewport meta tag, essential for responsive web design on mobile devices. It explains how proper use ensures optimal content scaling and user interaction, while misuse can lead to design and accessibility issues.

What is the purpose of the <iframe> tag? What are the security considerations when using it? What is the purpose of the <iframe> tag? What are the security considerations when using it? Mar 20, 2025 pm 06:05 PM

The article discusses the &lt;iframe&gt; tag's purpose in embedding external content into webpages, its common uses, security risks, and alternatives like object tags and APIs.

The Roles of HTML, CSS, and JavaScript: Core Responsibilities The Roles of HTML, CSS, and JavaScript: Core Responsibilities Apr 08, 2025 pm 07:05 PM

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

What is an example of a starting tag in HTML? What is an example of a starting tag in HTML? Apr 06, 2025 am 12:04 AM

AnexampleofastartingtaginHTMLis,whichbeginsaparagraph.StartingtagsareessentialinHTMLastheyinitiateelements,definetheirtypes,andarecrucialforstructuringwebpagesandconstructingtheDOM.

See all articles