html部分
<div class="box"></div>
css部分
.box{
width: 100px;
height: 100px;
position: relative;
display: flex;
justify-content: center;
align-items: center;
margin: 0 auto;
box-shadow: none;
background: coral;
}
原生js部分
window.onload=function(){
let box = document.querySelector(".box");
//打印你所要属性值
console.log(getClassStyle(box,"width"));
function getClassStyle(obj,name){
let val;
if(obj.currentStyle){
val = obj.currentStyle[name];
}else{
val = getComputedStyle(obj,null)[name];
}
return val;
}
}