We all know the position value of the position attribute in CSS. Besides the default value, there are absolute, relative, and fixed. I usually use absolute and relative, but I don't pay much attention to position: fixed. It may be because the position: fixed mentioned in the CSS Chinese manual shows that "IE5.5 and NS6 do not support this attribute.
Some time ago, when creating a project, a layer should be fixed relative to the browser border. At that time, I tried using position: absolute and found that absolute is for the webpage border. Later, I checked some JavaScript statements that dynamically changed the left and top values based on the movement of the scroll bar. Although they can achieve similar results, when the scroll bar moves, the layer is shaking, and it doesn't look good. I want a way to fix the layer.
See the following code:
The code is as follows: |
Copy code |
<Style type = "text/css"> <! -- # Help { Width: 30px; Height: 20px; Background-color: green; Position: fixed; Left: 60px; Top: 100px; } --> </Style>
|
We use the above code to define a layer "help" (id = "help") on the page "). In this way, we can achieve the desired effect.
In IE 8, Firefox, Opera, Google and other browsers, there is no problem, but in earlier versions of IE, this attribute is invalid.
Example
The code is as follows: |
Copy code |
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <Html xmlns = "http://www.w3.org/1999/xhtml"> <Head> <Meta http-equiv = "Content-Type" content = "text/html; charset = utf-8"/> <Title> demo </title> <Style> # Top { Border: 1px solid blue; Background: # ccc; Width: 200px; Height: 150px; Position: fixed; _ Position: absolute; Bottom: 0; Right: 0; _ Top: expression(eval(document.documentElement.scrollTop+document.doc umentElement. clientHeight-this.offsetHeight-(parseInt (this. currentStyle. marginTop, 10) | 0)-(parseInt (this. currentStyle. marginBottom, 10) | 0 ))); } * Html { Background-image: url (about: blank ); Background-attachment: fixed; } </Style> </Head> <Body> <Br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <Div id = "top"> Test results </Div> </Body> </Html> |