Compare the differences between height:100% and Height:inherit in CSS

Source: Internet
Author: User

Inherit is a good thing not only to save code, especially to deal with background, but also to maintain.

However, if you want to inherit background's picture, you cannot abbreviate it, and it will look naïve:

Background: #fff inherit left top;

You can do this:

Background-image:inherit;

Similarities and differences between height:100% and Height:inherit

1. Compatibility difference
height:100% ie6+√
Height:inherit ie8+√

2. Most of the cases are The same
remove compatibility, in most cases, the same effect, and even difficult to think of different reasons. The

① the parent container height:auto, regardless of height:100% or height:inherit performance is auto.
② parent container is set high height:100px, regardless of height:100% or height: The Inherit performance is 100px high.

Is there no difference? Is there no reason to use Height:inherit? Of course, remember, all the things happened on the river, it is no coincidence!

3. Absolute positioning is very different
when the child element is an absolute positioning element, at the same time, the parent container position value is static, hehe, height:100% and height:inherit differences can be clearly reflected!

hehe

You can ruthlessly click here: height:100% and Height:inherit diff demo

css as follows:

The code is as follows Copy Code
. outer {
Display:inline-block;
height:200px; width:40%;
border:5px solid #cd0000;
}
. height-100 {
Position:absolute;
height:100%; width:200px;
Background-color: #beceeb;
}
. height-inherit {
Position:absolute;
Height:inherit; width:200px;
Background-color: #beceeb;
}



HTML is as follows:

The code is as follows Copy Code
<div class= "outer" ><div class= "height-100" ></div></div>
<div class= "outer" ><div class= "Height-inherit" ></div></div>



As a result, height:100% to break through the clouds, oh, no, is the depth of the region hell:


And Height:inherit is perfect and highly adaptive. No parent element of the positioning attribute:


I don't explain why I know everything about absolute positioning.

In short, here, height:inherit powerful and useful can be seen. Back, the container height changes, inside the absolute positioning element is still highly adaptive. This is a great feature, because if the page is complex, avoiding position:relative will make you less likely to go through a lot of z-index clutter levels.

Related Article

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.