【发布时间】:2022-11-29 23:21:41
【问题描述】:
大家好,我想使用 getComputedStyle 来访问 css 属性,不幸的是它只有 console.log() 的标准属性。
下面你会找到我的代码。
在图片上,您会发现它注销的内容。
`
<body>
<div id="box">box</div>
<script>
const box = document.getElementById("box");
const boxCS = window.getComputedStyle(box)
console.log(boxCS.zIndex)
</script>
</body>
<style>
#box {
width: 100px;
height: 100px;
border: 1px solid black;
position: absolute;
z-index: 1;
background-color: rgb(200, 200, 200);
}
</style>
`
【问题讨论】:
-
因为您将样式标签放在脚本标签之后(实际上在甚至无效的主体之外)。
标签: javascript html css getcomputedstyle