开发者

CSS horizontal scroll (simple)

开发者 https://www.devze.com 2023-02-07 18:43 出处:网络
Given: <div class=\"pageNavWrap\"> <a class=\"pageLink\" href=\"#\">1</a> <a class=\"pageLink\" href=\"#\">2</a>

Given:

        <div class="pageNavWrap">
            <a class="pageLink" href="#">1</a>
            <a class="pageLink" href="#">2</a>
        开发者_如何学运维    <a class="pageLink" href="#">3</a>
            <a class="pageLink" href="#">4</a>
            <a class="pageLink" href="#">5</a>
            <a class="pageLink" href="#">6</a>
            <a class="pageLink" href="#">7</a>
            <a class="pageLink" href="#">8</a>
            <a class="pageLink" href="#">9</a>
            <a class="pageLink" href="#">10</a>
            <a class="pageLink" href="#">11</a>
            <a class="pageLink" href="#">12</a>
            <a class="pageLink" href="#">13</a>
        </div>

With:

.pageNavWrap{
    background-color:#666;
    text-align:center;
    font-size:16px;
    overflow-x:scroll;
}
a.pageLink{
    color:White;
    padding-left:10px;
    padding-right:10px;
    padding-top:5px;
    padding-bottom:5px;
}

How can I stop the links overflowing downwards? I would like them to overflow-x only (already specified in CSS) so that the horizontal scroll bar comes into play.

Cheers!


you need to add

white-space:nowrap;

Browsers don't all seem to agree about inheritance on this attribute so try adding it to both css rules.


have you tried adding display:inline to the a.pageLink class


Overflow-x might not be the best option as we are still waiting for all browsers to adopt all CSS3 features.

From a user experience point of view, do you really need the 13 (or more) pagination results? If you decide yes, then I would consider making your pagination results into a list and left-float the li's with a css declaration display:inline;

To force your list to always appear on one line, consider white-space:nowrap


If you're not picky about browser compatibility:

.pageNavWrap
{
  display: table-row;
}
.pageLink
{
  display: table-cell;
}

and I was going to suggest white-space: nowrap; as well but @Noel Walters beat me to it.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号