The CSS implementation method that the DIV is always fixed at the bottom right corner of the webpage. The top function is returned.

Source: Internet
Author: User

I have found several implementation methods on the internet, and I feel that the third method works well.

Instance 1

DIV is always fixed in the lower right corner of the page CSS implementation method, a practical tip effect, based on CSS-Div, after opening the page is always displayed in the lower right corner, dragging the scroll bar is still fixed in the lower right corner will not change, through this CSS code disconnection, you will have a deeper understanding of the CSS layer Positioning method, which will be of great help for later compilation of CSS.
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <br/> <HTML xmlns = "http://www.w3.org/1999/xhtml"> <br/> <pead> <br/> <meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8 "/> <br/> <title> div is always fixed in the lower right corner of the webpage. </title> <br/> <MCE: style> <! -- <Br/> body {margin: 0; padding: 0 10px 0 10px; Height: 100%; overflow: auto; Background: #333; font-size: 12px ;} <br/> # wrap {display: block; bottom: 0px; Right: 1px! Important; Right: 18px; width: 200px; line-Height: 30px; position: fixed; Border: 1px solid # FFF; text-align: center; color: # FFF; Background: #000 ;}< br/> * HTML {overflow-X: auto; overflow-Y: auto ;}< br/> * html # wrap {position: absolute ;} <br/> --> </MCE: style> <style mce_bogus = "1"> body {margin: 0; padding: 0 10px 0 10px; Height: 100%; overflow: auto; Background: #333; font-size: 12px ;}< br/># wrap {display: block; bottom: 0px; Right: 1 Px! Important; Right: 18px; width: 200px; line-Height: 30px; position: fixed; Border: 1px solid # FFF; text-align: center; color: # FFF; Background: #000 ;}< br/> * HTML {overflow-X: auto; overflow-Y: auto ;}< br/> * html # wrap {position: absolute ;} </style> <br/> </pead> <br/> <body> <br/> <div> <a href = "# Top" mce_href = "# Top"> top </a> </div> <br/> <Div style = "height: 3986px; "> </div> <br/> <Div id =" Wrap "> I don't know what to do. Only this part belongs to me, before you change my location. <Br> <br/> <a href = "# Top" mce_href = "# Top"> return to the top </a> <br/> </div> <br/> <body> <br/> </ptml> <br/>

 

From: http://www.csrcode.cn/html/txdm/tcys/1058.htm

 

Instance 2

Debugging compatibility: IE6 IE7 IE8 ff, because IE6 is not compatible with position: fixed, which is compatible with hack processing in the code.

The first version shows a small button in the lower right corner as long as the scroll bar rolls the content to the top. The code and running effect are as follows:

 <! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <br/> <HTML xmlns = "http://www.w3.org/1999/xhtml"> <br/> <pead> <br/> <meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8 "/> <br/> <title> untitled document </title> <br/> </pead> <br/> <MCE: style type = "text/CSS"> <! -- <Br/> body {margin: 0px; padding: 0px; width: 1000px; margin-left: auto; margin-Right: auto} <br/> # box {float: left; width: 1000px; Background-color: # CCC ;}< br/> # gotopbtn {position: fixed; Right: 20px; bottom: 20px; width: 100px; height: 30px; line-Height: 30px; cursor: pointer; color: # FFF; Background-color: # f63; text-align: center; font-size: 12px; _ Position: absolute; _ Right: auto; _ left: expression (eval (document. do Cumentelement.scrollleft?document.doc umentelement. clientWidth-this.offsetWidth)-(parseint (this. currentstyle. marginleft, 10) | 0)-(parseint (this. currentstyle. marginright, 20) | 0); _ top: expression(eval(document.documentelement.scrolltop#document.doc umentelement. clientHeight-this.offsetHeight-(parseint (this. currentstyle. margintop, 10) | 0)-(parseint (this. currentstyle. marginbottom, 20) | 0) ;}< br/> --> </MCE: Style> <style type = "text/CSS" mce_bogus = "1"> body {margin: 0px; padding: 0px; width: 1000px; margin-left: auto; margin-Right: auto} <br/> # box {float: Left; width: 1000px; Background-color: # CCC ;}< br/> # gotopbtn {position: fixed; right: 20px; bottom: 20px; width: 100px; Height: 30px; line-Height: 30px; cursor: pointer; color: # FFF; Background-color: # f63; text-align: center; font-size: 12px; _ Position: absolute; _ Right: Uto; _ left: expression(eval(document.documentelement.scrollleft?document.doc umentelement. clientWidth-this.offsetWidth)-(parseint (this. currentstyle. marginleft, 10) | 0)-(parseint (this. currentstyle. marginright, 20) | 0); _ top: expression(eval(document.documentelement.scrolltop#document.doc umentelement. clientHeight-this.offsetHeight-(parseint (this. currentstyle. margintop, 10) | 0)-(parseint (this. currentstyle. m Arginbottom, 20) | 0) ;}</style> <br/> <MCE: Script Type = "text/JavaScript"> <! -- <Br/> function gotopex () {<br/> var OBJ = document. getelementbyid ("gotopbtn"); <br/> function getscrolltop () {<br/> return document.doc umentelement. scrolltop; <br/>}< br/> function setscrolltop (value) {<br/> document.doc umentelement. scrolltop = value; <br/>}< br/> window. onscroll = function () {getscrolltop ()> 0? OBJ. style. display = "": obj. style. display = "NONE" ;}< br/> obj. onclick = function () {<br/> var gotop = setinterval (scrollmove, 10); <br/> function scrollmove () {<br/> setscrolltop (getscrolltop () /1.1); <br/> If (getscrolltop () <1) clearinterval (gotop ); <br/>}< br/> // --> </MCE: SCRIPT> <br/> <body> <br/> <Div id = "box"> <br/> <Div style = "float: Left; margin-left: 900px; display: inline; width: 100px; Height: 500px; Background-color: #990 "> </div> <br/> <Div style =" float: Left; margin-left: 900px; display: inline; width: 100px; height: 500px; Background-color: # C63 "> </div> <br/> <Div style =" float: Left; margin-left: 900px; display: inline; width: 100px; Height: 500px; Background-color: # f93 "> </div> <br/> <Div style =" float: Left; margin-left: 900px; display: inline; width: 100px; Height: 500px; Background-color: # 09c "> </div> <br/> <Div style = "float: Left; margin-left: 900px; display: inline; width: 100px; Height: 500px; Background-color: # 66c "> </div> <br/> <Div id =" gotopbtn "style =" display: none; "mce_style =" display: none; "> back to the top </div> <br/> <MCE: Script Type =" text/JavaScript "> <! -- <Br/> gotopex (); <br/> // --> </MCE: SCRIPT> <br/> </body> <br/> </ptml> </P> <p>

 

Instance 3

The small button "Back to Top" is still not displayed when the user scrolls the screen. The small button is quietly slid out only when the screen scroll stops.

<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <br/> <HTML xmlns = "http://www.w3.org/1999/xhtml"> <br/> <pead> <br/> <meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8 "/> <br/> <title> untitled document </title> <br/> </pead> <br/> <MCE: style type = "text/CSS"> <! -- <Br/> body {margin: 0px; padding: 0px; width: 1000px; margin-left: auto; margin-Right: auto} <br/> # box {float: left; width: 1000px; Background-color: # CCC ;}< br/> # gotopbtn {position: fixed; Right: 20px; bottom: 20px; width: 100px; height: 30px; line-Height: 30px; cursor: pointer; color: # FFF; Background-color: # f63; text-align: center; font-size: 12px; _ Position: absolute; _ Right: auto; _ left: expression (eval (document. do Cumentelement.scrollleft?document.doc umentelement. clientWidth-this.offsetWidth)-(parseint (this. currentstyle. marginleft, 10) | 0)-(parseint (this. currentstyle. marginright, 20) | 0); _ top: expression(eval(document.documentelement.scrolltop#document.doc umentelement. clientHeight-this.offsetHeight-(parseint (this. currentstyle. margintop, 10) | 0)-(parseint (this. currentstyle. marginbottom, 20) | 0) ;}< br/> --> </MCE: Style> <style type = "text/CSS" mce_bogus = "1"> body {margin: 0px; padding: 0px; width: 1000px; margin-left: auto; margin-Right: auto} <br/> # box {float: Left; width: 1000px; Background-color: # CCC ;}< br/> # gotopbtn {position: fixed; right: 20px; bottom: 20px; width: 100px; Height: 30px; line-Height: 30px; cursor: pointer; color: # FFF; Background-color: # f63; text-align: center; font-size: 12px; _ Position: absolute; _ Right: Uto; _ left: expression(eval(document.documentelement.scrollleft?document.doc umentelement. clientWidth-this.offsetWidth)-(parseint (this. currentstyle. marginleft, 10) | 0)-(parseint (this. currentstyle. marginright, 20) | 0); _ top: expression(eval(document.documentelement.scrolltop#document.doc umentelement. clientHeight-this.offsetHeight-(parseint (this. currentstyle. margintop, 10) | 0)-(parseint (this. currentstyle. m Arginbottom, 20) | 0) ;}</style> <br/> <MCE: Script Type = "text/JavaScript"> <! -- <Br/> function gotopex () {<br/> var OBJ = document. getelementbyid ("gotopbtn"); <br/> function getscrolltop () {<br/> return document.doc umentelement. scrolltop; <br/>}< br/> function setscrolltop (value) {<br/> document.doc umentelement. scrolltop = value; <br/>}< br/> window. onscroll = function () {<br/> var ST1 = getscrolltop (); <br/> var I = 0; <br/> var checkstop = setinterval (showgotop, 500 ); <br/> obj. style. display = "No Ne "; <br/> function showgotop () {<br/> If (getscrolltop () = ST1 & I> 1) {<br/> clearinterval (checkstop ); <br/> getscrolltop ()> 0? OBJ. style. display = "": obj. style. display = "NONE"; <br/> var Mm = setinterval (ssbtn, 20); <br/> obj. style. bottom = 0; <br/> var S = 0; <br/> function ssbtn () {<br/> If (S <21) {S + = 2; obj. style. bottom = S + "PX" ;}else {clearinterval (MM) }< br/>}< br/> I ++; <br/>}< br/> obj. onclick = function () {<br/> var gotop = setinterval (scrollmove, 10); <br/> function scrollmove () {<br/> setscrolltop (getscrolltop () /1.1); <br/> If (gets Crolltop () <1) clearinterval (gotop); <br/>}< br/> // --> </MCE: SCRIPT> <br/> <body> <br/> <Div id = "box"> <br/> <Div style = "float: Left; margin-left: 900px; display: inline; width: 100px; Height: 500px; Background-color: #990 "> </div> <br/> <Div style =" float: left; margin-left: 900px; display: inline; width: 100px; Height: 500px; Background-color: # C63 "> </div> <br/> <Div style =" float: Left; margin-left: 900 Px; display: inline; width: 100px; Height: 500px; Background-color: # f93 "> </div> <br/> <Div style =" float: left; margin-left: 900px; display: inline; width: 100px; Height: 500px; Background-color: # 09c "> </div> <br/> <Div style =" float: Left; margin-left: 900px; display: inline; width: 100px; Height: 500px; background-color: # 66c "> </div> <br/> <Div id =" gotopbtn "style =" display: none; "mce_style =" display: none; "> Back to the top </div> <br/> <MCE: Script Type =" text/JavaScript "> <! -- <Br/> gotopex (); <br/> // --> </MCE: SCRIPT> <br/> </body> <br/> </ptml> </P> <p>

Example 2, 3 from: http://www.52-ni.cn/index.php/archives/835

Sliding Door effects:

Http://www.csrcode.cn/html/txdm/tcys/2542.htm

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.