Inherit in CSS specifies the difference between the use of inheritance and auto

Source: Internet
Author: User

Each property in the CSS has a specific value of "inherit", which means that the corresponding property of the parent element is specified, using inherit on the one hand to indicate the style attributes to inherit from the parent element on the one hand, and the child element to inherit the attributes that are not automatically inherited.

Other words:

Inherit is a property that inherits from the parent class, typically used for fonts, colors, and so on, auto is adaptive, generally used for height, width, margin, and padding, etc. about length properties

If the designer wants the div element of class box to have a 2px black border, and has a 5px fill, and wants its sub-div element to have the same style,

You can write the following rules:

<!DOCTYPE HTML><HTML><Head>  <MetaCharSet= "Utf-8">  <title>JS Bin</title>  <style>    /*enables child elements to inherit attributes that are not automatically inherited*/. Box{Border:2px solid Black;padding:5px;background:#ccc;Height:100px;    }. Box Div{      /*use inherit to inherit attributes from parent, unlike auto*/Border:Inherit;padding:Inherit;Height:Auto;    }  </style></Head><Body>  <Divclass= ' box '>dad<Div>Son</Div>      </Div></Body></HTML>

On-line debugging: Inherit and Auto differences

Http://jsbin.com/fuwiyo/3/edit?html,output

Inherit in CSS specifies the difference between the use of inheritance and auto

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.