Because I need to locate the height of an HTML element (for example: div) from the top of the page, I want to use offsetTop to get the value. However, I find that if float:left; is used in CSS, the value will be obtained. no the same.
Float:left is not used; the value obtained is the normal value of 200;
nbsp;html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
The impact of Float on offsetTop body {margin:0;padding: 0;}
#Top {height:100px;}
#Main {padding:100px;} #IECN {width:200px;height:50px;background:#f00;color:#fff;}
#Main {padding:100px;} does not use the float attribute, the value of offsetTop obtained Normal: 200.
Click here to try
nbsp;html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Used float :left;, the value became 100, which was 100 less for no reason
The impact of Float on offsetTop
#Main {padding:100px;float:left;} uses the float attribute, The value of offsetTop obtained is only 100, which is 100 less for no reason.