3

如何让 height: 100% 起作用

 2 years ago
source link: https://blog.huangyafei.com/post/2015-07-12/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

如何让 height: 100% 起作用

如果想让一个元素的百分比高度 height: 100%; 起作用,那么你需要给这个元素的所有父元素的高度设定一个有效值,如:

<html> <body> <div style="height: 100%;"> <p> 想让这个div高度为 100% 。 </p> </div> </body> </html>

现在你给了这个 div 的高度为 100%,它有两个父元素 <body><html>。为了让你的 div 的百分比高度能起作用,你必须设定 <body><html> 的高度。

<html style="height: 100%;"> <body style="height: 100%;"> <div style="height: 100%;"> <p> 这样这个div的高度就会100%了 </p> </div> </body> </html>

来源:http://www.webhek.com/css-100-percent-height


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK