css – 当position:fixed时无法获取滚动 – 元素从屏幕上消失

前端之家收集整理的这篇文章主要介绍了css – 当position:fixed时无法获取滚动 – 元素从屏幕上消失前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
顶级栏(固定) – 正如在Twitter和Facebook上看到的那样,试图模仿我正在进行的网络项目 – 无论我尝试多少,内容都会消失在滚动之外.本教程 http://www.sohtanaka.com/web-design/facebook-style-footer-admin-panel-part-1/

但是,当分辨率改变或缩放时,内容会重叠.不要这样 – 正如我们在twitter / FB上看到的那样 – 希望滚动显示变焦(或更低的分辨率)

自2天以来一直在围绕这个问题,没有积极的结果.

这是我从教程中编辑的测试代码

  1. <html>
  2. <style type="text/css">
  3. #footpanel {
  4. position: fixed;
  5. top: 0; left: 0;
  6. z-index: 9999;
  7. background: #e3e2e2;
  8. border: 1px solid #c3c3c3;
  9. border-top: none;
  10. width: 100%;
  11. height: 25px;
  12. }
  13. #footpanel ul {
  14. padding: 0; margin: 0;
  15. float: left;
  16. width: 100%;
  17. list-style: none;
  18. border-bottom: 1px solid #fff; /*--Gives the bevel feel on the panel--*/
  19. }
  20. #footpanel ul li{
  21. padding: 0; margin: 0;
  22. float: left;
  23. position: relative;
  24. }
  25. #footpanel ul li a{
  26. padding: 5px;
  27. float: left;
  28. height: 16px; width: 36px;
  29. text-decoration: none;
  30. color: black;
  31. position: relative;
  32. }
  33. #footpanel a.home{
  34. width: 50px;
  35. padding-left: 40px;
  36. border-right: 1px solid #bbb;
  37. text-indent: 0; /*--Reset text indent since there will be a combination of both text and image--*/
  38. }
  39. #footpanel a.chat{
  40. width: 126px;
  41. border-left: 1px solid #bbb;
  42. border-right: 1px solid #bbb;
  43. padding-left: 40px;
  44. text-indent: 0; /*--Reset text indent since there will be a combination of both text and image--*/
  45. }
  46. #footpanel li#chatpanel,#footpanel li#alertpanel { float: right; } /*--Right align the chat and alert panels--*/
  47.  
  48. </style>
  49.  
  50. <div id="footpanel">
  51. <ul id="mainpanel">
  52. <li><a href="#" class="home">A </a></li>
  53. <li><a href="#" class="profile">B </a></li>
  54. <li><a href="#" class="editprofile">C </a></li>
  55. <li><a href="#" class="contacts">D </a></li>
  56. <li><a href="#" class="messages">E </a></li>
  57. <li><a href="#" class="playlist">P </a></li>
  58. <li><a href="#" class="videos">V </a></li>
  59. <li id="alertpanel"><a href="#" class="alerts">S</a></li>
  60. <li id="chatpanel"><a href="#" class="chat">F (<strong>18</strong>)</a></li>
  61. </ul>
  62. </div>
  63.  
  64. </html>

发生了什么 – 在缩放(或更低的分辨率)脚板的内容出来(我可以防止这个溢出:隐藏,但这不是我想要的)容器(footpanel)

我想要它做什么 – 比如twitter / FB,我想要一个滚动进来和脚板来保存它的布局而不是不合适.

请帮忙
–CSS初学者

解决方法

我想不出在纯CSS中这样做的方法和Twitter似乎使用Javascript来实现这种效果.

首先,在#footpanel和body上设置相同的min-width.您可能还希望将各种项目的高度设置为auto或em等效项,以便在缩放和文本大小调整时很好地调整大小.

然后将此Javascript放在您的页面上:

  1. <script type="text/javascript">
  2. function hscrollbar() {
  3. /* First,we need the horizontal scroll position of the viewer's display,but there are different ways to call it in JS depending on browser.
  4. I'm using the if/else shorthand notation to detect if a call is legit:
  5. somevar = (statement) ? statement_true_value : statement_false_value */
  6. var left =
  7. /* window.pageXOffset should work for most recent browsers: */
  8. window.pageXOffset ? window.pageXOffset :
  9. /* If it DOESN'T,let's try this: */
  10. document.documentElement.scrollLeft ? document.documentElement.scrollLeft :
  11. /* And if THAT didn't work: */
  12. document.body.scrollLeft;
  13.  
  14. /* Now that we have the horizontal scroll position,set #footpanel's left
  15. position to NEGATIVE the value,so it APPEARS to follow the scroll: */
  16. document.getElementById('footpanel').style.left = -left;
  17. }
  18. window.onscroll = hscrollbar; /* Call the function when the user scrolls */
  19. window.onresize = hscrollbar; /* Call the function when the window resizes */
  20. </script>

删除灰色的所有注释以取消代码

猜你在找的CSS相关文章