Get questions about style

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
* {
margin: 0;
padding: 0;
}
input {
margin-top: 20px;
}
div {
margin-top: 30px;
width: 200px;
height: 100px;
background-color: pink;
position: absolute;
left: 0;
}
</style>
</head>
<body>
<input type="button" value="移动到400px" id="btn1" style="background-color:red;left: 0;">
<input type="button" value="移动到800px" id="btn2">
<div id="dv"></div>
<script src="common.js"></script>
<script>
// If the style code is re-set style tag outside (style.left) is less than the acquired 
// If the style code is re-set style attributes, is acquired outside style.left
console.log (document.getElementById ( "btn1") style.backgroundColor.); // can get 
console.log (document.getElementById ( "btn1") style.left.); // can get
console.log (document. getElementById ( "dv") style.left) ;. // not get
console.log (document.getElementById ( "dv") style.backgroundColor);. // not get
  console.log (document.getElementById ( "dv ") .offsetLeft); // can obtain a digital type, no px
</script>
</body>
</html>

Guess you like

Origin www.cnblogs.com/chm-blogs/p/11307273.html