CSS水平滚动问题

前端之家收集整理的这篇文章主要介绍了CSS水平滚动问题前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
问题

我需要强制内容在X轴上滚动,而不是在Y轴上滚动.

HTML

我知道这格式很糟糕但它是动态生成的并且没有空格.

  1. <div class="folderWrapper" id="folderContainer"><div class="folderBox ui-droppable folderBoxSel" onclick="folderSelected(0)" id="fBox0"><div class="counter" id="fCount0">4</div><div class="folderName">Unsorted</div></div><div class="folderBox ui-droppable" onclick="folderSelected(1)" id="fBox1"><div class="counter" id="fCount1">0</div><div class="folderName">test</div></div><div class="folderBox" onclick="folderSelected(1)" id="fBox1"><div class="counter" id="fCount1">0</div><div class="folderName">test</div></div><div class="folderBox" onclick="folderSelected(1)" id="fBox1"><div class="counter" id="fCount1">0</div><div class="folderName">test</div></div><div class="folderBox" onclick="folderSelected(1)" id="fBox1"><div class="counter" id="fCount1">0</div><div class="folderName">test</div></div><div class="folderBox" onclick="folderSelected(1)" id="fBox1"><div class="counter" id="fCount1">0</div><div class="folderName">test</div></div></div>

使用一个文件夹内部框格很好地格式化:

  1. <div class="folderWrapper" id="folderContainer">
  2. <div class="folderBox ui-droppable folderBoxSel" onclick="folderSelected(0)" id="fBox0">
  3. <div class="counter" id="fCount0">4</div>
  4. <div class="folderName">Unsorted</div>
  5. </div>
  6. </div>

CSS

  1. .folderWrapper{
  2. overflow-x:scroll;
  3. overflow-y:hidden;
  4. height:85px;
  5. white-space:nowrap;
  6. margin-bottom:5px;
  7. }
  8. .folderBox{
  9. float:left;
  10. background-image:url(../images/artworking/folder.png);
  11. background-position:center top;
  12. background-repeat:no-repeat;
  13. width:85px;
  14. height:55px;
  15. position:relative;
  16. padding:5px;
  17. z-index:4;
  18. white-space:nowrap;
  19. }
  20. .folderBox:hover{
  21. cursor: pointer;
  22. }

谢谢,如果有人可以帮助!

编辑

Bazzz的答案适用于所有浏览器,除了IE兼容模式(不幸的是它必须兼容),它具有以下外观:

随着IE黑客:

解决方法

在你的folderBox上使用inline-block而不是float:left
  1. .folderBox{
  2. float: left; /* remove this line */
  3. display: inline-block; /* add this line */
  4. }

空白:no-wrap不适用于浮动元素,它适用于内联元素.

对于IE 7,我发现了一个可以帮助你的小黑客:

http://blog.mozilla.com/webdev/2009/02/20/cross-browser-inline-block/

试试这个css:

  1. .folderBox{
  2. display: inline-block;
  3. zoom: 1;
  4. *display: inline;
  5. }

最近编辑:

此css适用于IE 8 compat模式(IE7标准):

  1. .folderWrapper{
  2. overflow-x: scroll;
  3. overflow-y: hidden;
  4. height:85px;
  5. width: 300px; /* not really your css,I used it in my test case */
  6. white-space:nowrap;
  7. }
  8. .folderBox{
  9. display: inline-block;
  10. zoom: 1;
  11. *display: inline;
  12. background-image:url(../images/artworking/folder.png);
  13. background-position:center top;
  14. background-repeat:no-repeat;
  15. width:85px;
  16. height:55px;
  17. }

我相信IE7中的非溢出问题在于:您使用的相对位置.我删除它,和其他一些CSS,现在它的工作原理.

猜你在找的CSS相关文章