铬 51 结果
火狐结果
测试.js
(function(){
let template = `
<style>
@import url("css/test.css");
.test1{
height: 100px;
width: 100px;
color: #fff;
background-color: var(--main-bg-color,red);
}
</style>
<div class="test1">test</div>
<div class="test2">test2</div>
`;
class TestWidget extends HTMLElement{
createdCallback(){
this.createShadowRoot().innerHTML = template;
};
}
document.registerElement('test-widget',TestWidget);
})();
测试.css
:root{
--main-bg-color: blue;
}
.test2{
background-color: green;
height: 100px;
width: 100px;
color: #fff;
}
测试.html
<test-widget></test-widget>
为什么两个不同浏览器的结果不一样?