Home >Web Front-end >JS Tutorial >Use js to define the position of a left and right floating element in the browser relative to the width of the page body_javascript skills

Use js to define the position of a left and right floating element in the browser relative to the width of the page body_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:56:55815browse

First, the position of this element is fixed
top is (clientHeight-elem.offsetHeight)/2 (that is, the element is in the middle of the browser, this is fixed)
left is (clientWidht-body width)/2 left of the body width The left margin can be set to a positive number or a negative number. If the absolute value when it is a negative number is equal to the body width elem.offsetWidht, then the element will just float to the left of the page body. When it is set to 0, it will just float on the page body. On the right
But the evil ie6 does not support the fixed attribute in css. Fortunately, ie6 can solve it through expression expressions, and everything will be fine
Look at the code specifically:

Copy the code The code is as follows:





Left and right floating elements