当前位置:Gxlcms > css > css控制div固定在浏览器底部实例代码

css控制div固定在浏览器底部实例代码

时间:2021-07-01 10:21:17 帮助过:4人阅读

css控制div固定在浏览器底部

注意:此功能仅用于页面高度较小页面。

css控制div固定在浏览器底部实例代码

代码如下:

  1. <html>
  2. <head>
  3. <style type="text/css">
  4. body{
  5. margin:0px;
  6. }
  7. #main{
  8. width:100%;
  9. height:50px;
  10. position:absolute;
  11. top:100%;
  12. margin-top:-50px;
  13. background:#360;
  14. color:white;
  15. }
  16. </style>
  17. </head>
  18. <body>
  19. <div style="border:1px solid #f00;width:500px;height:1800px"></div>
  20. <div id="main">bottom</div>
  21. </body>
  22. </html>

网上找了个更好的:

当浏览器窗口无限缩小,向右拖动滚动条不会出现空白。

css控制div固定在浏览器底部实例代码

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=gbk" />
  5. <title>ie6层固定</title>
  6. <style type="text/css">
  7. <!--
  8. .bookbox {
  9. background-color: #09C;
  10. height: 30px;
  11. width: 100%;
  12. position: fixed;
  13. bottom: 0px;
  14. left: auto;
  15. right: auto;
  16. line-height: 30px;
  17. text-align: center;
  18. _POSITION: absolute;/*兼容IE6*/
  19. _TOP: expression(offsetParent.scrollTop+document.documentElement.clientHeight-this.offsetHeight);/*兼容IE6*/
  20. }
  21. .bookbox a{color: #FFF;}
  22. -->
  23. </style>
  24. </head>
  25. <body>
  26. <div style="border:1px solid #f00;width:500px;height:2000px;">这个例子是实现层固定在浏览器窗口的最下面,兼容IE6.<br />
  27. <br />
  28. 往下看,看页面的最下面</div>
  29. <div class="bookbox">测试测试测试测试测试测试测试测试测试测试测试测试测试测试</div>
  30. </body>
  31. </html>

恩,感觉上面的对不是很好,这里网上找了个,挺实用的:

css控制div固定在浏览器底部实例代码

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  5. <style type="text/css">
  6. html, body {
  7. height: 100%;
  8. overflow-y: auto
  9. }
  10. body, div, p, ul, ol, li, form, input {
  11. padding: 0; margin: 0;
  12. }
  13. body{
  14. position:relative;
  15. background: #fff;
  16. }
  17. #wp {
  18. border:1px solid #00f;
  19. height: auto;
  20. min-height: 100%;
  21. _height: 100%;
  22. }
  23. #ft {
  24. border:1px solid #f00;
  25. margin-top: -157px;
  26. padding: 50px 0 0;
  27. }
  28. #sc {
  29. border:1px solid #f00;
  30. width: 580px;
  31. margin: 0 auto;
  32. padding-left: 20px;
  33. padding-bottom: 157px;
  34. }
  35. #s {
  36. border:1px solid #f00;
  37. position: relative;
  38. height: 33px;
  39. z-index:9
  40. }
  41. </style>
  42. </head>
  43. <body>
  44. <div id="wp">
  45. <div id="sc">
  46. <div id="s"></div>
  47. </div>
  48. </div>
  49. <div id="ft">
  50. </div>
  51. </body>
  52. </html>

以上就是css控制div固定在浏览器底部实例代码的详细内容,更多请关注Gxl网其它相关文章!

人气教程排行