What is the difference between height:100% and height:auto?

零下一度
Release: 2017-06-30 16:29:43
Original
16766 people have browsed it

I have never understood the difference between height:100% and height:auto. Recently, I have used height:100%;overflow:hidden; when making front-end pages, but some browsers have inexplicable and wonderful problems. But just change it to height:auto. Baidu has never looked into this problem in detail.

The same problem came up again today. After a closer look at Baidu and the guidance of friends in the group, I finally understood the reason and recorded it.

height:auto refers to automatically adjusting the height according to the content in the block.
height:100% refers to the height defined relative to the height of the parent block, that is, the height is defined based on the height of the parent layer that is closest to it and has a defined height.

auto expands according to the height of the content. 100% is determined based on the height of the parent element. For example:

<div style="height:100px;width:200px;">      <div style="height:auto;width:100px;float:left;">
这个容器的高度是随里面的内容的高度而定
</div>
Copy after login
<div style="height:100%;width:100px;float:right;">这个容器的高度为父级的高度,100px</div> </div>
Copy after login

For example, a table is inside another table. If the height of the outside table is 100 and the inside table is auto, if there is nothing in the table, it will have no height. The content inside the table is How high it is, and when it is 100%, regardless of whether there is content inside, it will be the same height as the outside table

The above is the detailed content of What is the difference between height:100% and height:auto?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!