<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>css</title>
<style type="text/css">
.dd {
color: #f00;
}
.bd {
border: 1px solid #000;
}
.width {
width: 200px;
}
</style>
</head>
<body>
<div id="dd" class="dd bd width">我去</div>
<script>
var obj = document.getElementById('dd')
function getstyle(sname) {
for (var i = 0; i < document.styleSheets.length; i++) {
var rules;
if (document.styleSheets[i].cssRules) {
rules = document.styleSheets[i].cssRules;
} else {
rules = document.styleSheets[i].rules;
}
for (var j = 0; j < rules.length; j++) {
if (rules[j].selectorText == sname) {
return rules[j].style;
}
}
}
}
window.onresize = function() {
getstyle('.width').width = document.documentElement.clientHeight + 'px'
}
</script>
</body>
</html>