6

问题

在此处输入图像描述 在此处输入图像描述

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

HTML

我知道这是格式错误,但它是动态生成的并且没有空格。

<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>

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

<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>

CSS

.folderWrapper{
    overflow-x:scroll;
    overflow-y:hidden;
    height:85px;
    white-space:nowrap;
    margin-bottom:5px;
}
.folderBox{
    float:left;
    background-image:url(../images/artworking/folder.png);
    background-position:center top;
    background-repeat:no-repeat;
    width:85px;
    height:55px;  
    position:relative;
    padding:5px;
    z-index:4;
    white-space:nowrap;
}
.folderBox:hover{
    cursor: pointer;
}

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

编辑

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

在此处输入图像描述

使用 IE 破解:

在此处输入图像描述

4

2 回答 2

8

在您的 folderBox 上使用inline-block,而不是float:left

.folderBox{
    float: left; /* remove this line */
    display: inline-block; /* add this line */
}

whitespace: no-wrap 不适用于浮动元素,它适用于内联元素。

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

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

试试这个CSS:

.folderBox{
 display: inline-block;
 zoom: 1;
 *display: inline;
 }

最新编辑:

这个 css 在 IE 8 兼容模式(IE7 标准)下工作:

.folderWrapper{
    overflow-x: scroll;
    overflow-y: hidden;
    height:85px;
    width: 300px; /* not really your css, I used it in my test case */
    white-space:nowrap;
}
.folderBox{
    display: inline-block;
    zoom: 1;
    *display: inline;
    background-image:url(../images/artworking/folder.png);
    background-position:center top;
    background-repeat:no-repeat;
    width:85px;
    height:55px;  
}

我相信IE7中的非溢出问题在于position:relative你使用的那个。我删除了它,以及其他一些 css,现在它可以工作了。

于 2011-02-03T11:00:15.057 回答
0

我会创建像这样的 HTML:

<div id="folderWrapper">
     <ul id="folderList">
         <li class="folderBox">...</li>
         <li class="folderBox">...</li>
         <li class="folderBox">...</li>
     </ul>
</div>

和 CSS:

#folderWrapper {
    position:relative;
    z-index:1;
    width:300px;
    overflow:hidden;
}
#folderList {
    position:absolute;
    z-index:2;
    width:20000px;
}
.folderBox {
    float:left;
}

然后在#folderWrapper 中使用基于jquery 的滚动条:http: //www.net-kit.com/jquery-custom-scrollbar-plugins/

我喜欢 jScrollPane。

于 2011-02-03T13:24:45.580 回答