[英]Set element's height to <body>'s width and its width to <body>'s height dynamically
[英]set the body height width css expressions
我想用css表達式動態改變體高..我的代碼是
HTML
<body >
<div class="tall_top" >
</div>
</body>
CSS
body {
width: 100px;
height: expression(document.documentElement.clientHeight);
background: red;
}
.tall_top {
background:#f1f1f1;
width:50%;
height:50%
}
但它不適用於谷歌瀏覽器......內部div沒有顯示。 檢查元件中顯示的主體高度為0px;
JS小提琴
div.tall_top
沒有顯示,因為你的body,html
沒有高度。
將高度設置為100%
html,body {
margin:0;
width:100%;
height:100%;
background:blue;
}
css表達式不值得學習了。 使用JavaScript或css媒體查詢 。 而且它也會產生瀏覽器兼容性問題,因為它只支持IE6 / 7(可能)5。
您的expression
主要是評估窗口的高度,通常是<html>
元素的高度。
添加這個CSS應該工作:
html, body {
height: 100%;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.