7

我有以下结构:

#navBar {
    height: 55px;
    width: 40px; 
    overflow-x:scroll; 
    overflow-y:hidden;
}

<div id="navBar">
akdhbaIDBhbfbhwhfbaibf
    <div style="width: 80; float: left;  text-align: center;">
    <img src="http://192.168.2.105/SB_Site/icons/Home2.jpg" alt="Nav1" />
    <br />
    <span style="font-size: 80%">Nav1</span>
    </div>
    <div style=" width: 80; float: left;  text-align: center;">
    <img src="http://192.168.2.105/SB_Site/icons/Home2.jpg" alt="Nav2" />
    <br />
    <span style="font-size: 80%">Nav2</span>
    </div>
    <div style=" width: 80; float: left;  text-align: center;">
    <img src="http://192.168.2.105/SB_Site/icons/Home2.jpg" alt="Nav3" />
    <br />
    <span style="font-size: 80%">Nav3</span>
    </div>
</div>

我希望所有的内在div意志都scroll-x不会打破界限。我怎样才能做到这一点?

4

3 回答 3

9

这将起作用:

<style type="text/css">
    #navBar {
        height: 55px;
        width: 80px;
        overflow-x: scroll;
        overflow-y:hidden;
        white-space: nowrap;
    }

    #navBar div {
        display: inline-block;
    }
</style>

对于 HTML 部分:

<div id="navBar">
        akdhbaIDBhbfbhwhfbaibf
        <div style="width: 100px; text-align: center; background-color: red;">
            <img src="" alt="Nav1" />
            <br />
            <span style="font-size: 80%">Nav1</span>
        </div>
        <div style=" width: 100px; text-align: center;">
            <img src="" alt="Nav2" />
            <br />
            <span style="font-size: 80%">Nav2</span>
        </div>
        <div style=" width: 100px; text-align: center; background-color: red;">
            <img src="" alt="Nav3" />
            <br />
            <span style="font-size: 80%">Nav3</span>
        </div>
</div>

不需要float: left;CSS。

于 2012-07-21T07:12:16.103 回答
2

添加white-space: nowrap到#navBar 和display: inline-block;内部div。我相信应该这样做。

看看这个小提琴:http: //jsfiddle.net/fzLwX/1/

于 2012-07-21T06:58:25.010 回答
0

这可能是您正在寻找的:

#navBar div{
    overflow-x:auto;
}
于 2012-07-21T06:43:06.357 回答