簡體   English   中英

如何將javascript變量傳遞給外部CSS文件?

[英]How to pass javascript variables to external css files?

我是編程和網頁設計的新手,我正在嘗試創建一個網站。 我的外觀計划是 這個

所以,我使用的代碼是

<body>
<div id="header">

</div>
<div id="content">

</div>
<div id="footer">

</div>



<script>
        function getWidth()
        {
            xWidth = null;
            if(window.screen != null)
                xWidth = window.screen.availWidth;

            if(window.innerWidth != null)
                xWidth = window.innerWidth;

            if(document.body != null)
                xWidth = document.body.clientWidth;

            return xWidth;
        }
        function getHeight() {
            xHeight = null;
            if(window.screen != null)
                xHeight = window.screen.availHeight;

            if(window.innerHeight != null)
                xHeight =   window.innerHeight;

            if(document.body != null)
                xHeight = document.body.clientHeight;

            return xHeight;
        }
</script>
</body>

之后,我創建了一個.css文件(為空)。 因此,我想創建一個從閱讀器屏幕上獲取可用寬度和高度的網站,然后在計算數字后顯示相對於可用寬度和高度的div,例如,小方框的高度=寬度= 5% .width_of_screen。 每個小盒子都會是一個項目或一個職位。

所以,我的問題是:如何在外部CSS中傳遞變量的數據來計算網站的數字?

謝謝加百列

您可以使用jQuery這樣設置CSS變量:

$("p").css({"background-color":"yellow","font-size":"200%"});

在這種情況下,您可以用變量替換“黃色”和“ 200%”。

暫無
暫無

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

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