簡體   English   中英

設置體高寬度css表達式

[英]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小提琴

http://jsfiddle.net/3x6fh/

div.tall_top沒有顯示,因為你的body,html沒有高度。

將高度設置為100%

    html,body {
        margin:0;
        width:100%;
        height:100%;
        background:blue;
    }

演示: http//jsfiddle.net/codef0rmer/3x6fh/2/

css表達式不值得學習了。 使用JavaScript或css媒體查詢 而且它也會產生瀏覽器兼容性問題,因為它只支持IE6 / 7(可能)5。

高性能網站:規則 - 避免CSS表達式

您的expression主要是評估窗口的高度,通常是<html>元素的高度。

添加這個CSS應該工作:

html, body {
  height: 100%;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM