标签:style ref href border html 区别 element script dem
css小记(一)最近有朋友问我css中offsetWidth,width,clientWidth,三者有什么区别,实际上这个问题非常简单,编写一个demo就能解决问题,总的说来一句话就能概括
clientWidth = width + padding
offsetWidth = width + padding + border
<html>
<head>
</head>
<body>
<div id=‘test‘ style="border:2px solid blue; padding:5px;width: 200px;">
baofengketang.com
</div>
<script>
var ele = document.getElementById(‘test‘);
//clientWidth:210 offsetWidth:214 width:200px
alert("clientWidth:"+ele.clientWidth+" offsetWidth:"+ele.offsetWidth+" width:"+ele.style.width);
</script>
</body>
</html>
好了,这个小点就讲这么多~~
欢迎关注我的网络课堂:http://edu.51cto.com/lecturer/11220344.html
标签:style ref href border html 区别 element script dem
原文地址:http://blog.51cto.com/11230344/2172958