![](/img/trans.png)
[英]How to add multiply styles document.documentElement.style.setProperty (js)
[英]document.documentElement.style.setProperty('--some-color', 'green') does not work in IE
我在選擇器的單獨 css 文件中聲明了一個自定義 css 變量。
.ui-grid-row:nth-child(odd) {
background-color: var(--altbg-color) !important;
}
這不是根元素。 所以不確定在這種情況下 css-vars-ponyfill 將如何工作。 我也嘗試過,但無法使其工作。 (如果有人能幫助我使它工作,我將不勝感激。)
我正在嘗試通過 javascript(我使用的是 AngularJS 1.3)為變量設置值
document.documentElement.style.setProperty('--some-color', 'green')
它適用於 Chrome 和 Firefox,但不適用於 IE(11)。
有人有解決方案嗎?
提前致謝。
您只能使用 IE edge 16 及更高版本的 CSS 變量。 但是,它在 IE 15 中得到部分支持。
不過,有一個 polyfill:
https://www.npmjs.com/package/css-vars-ponyfill
這不支持 IE edge 11。它開始支持 IE edge 12+。 沒有邊緣,它從 IE 9 開始支持。
IE Edge Chrome Firefox Safari
----------------------------------
9+ 12+ 19+ 6+ 6+
有一個 polyfill,它幾乎可以完全支持 IE11 中的 CSS 變量,包括 JS 集成:
https://github.com/nuxodin/ie11CustomProperties
(我是作者)
該腳本利用了這樣一個事實,即 IE 具有最少的自定義屬性支持,其中可以在考慮級聯的情況下定義和讀取屬性。
.myEl {-ie-test:'aaa'} // only one dash allowed! "-"
然后在javascript中閱讀它:
getComputedStyle( querySelector('.myEl') )['-ie-test']
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.