CSS水平滚动(简单)

发布于 2024-10-15 11:14:54 字数 1202 浏览 7 评论 0原文

鉴于:

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

与:

.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;
}

如何阻止链接向下溢出?我希望它们仅溢出-x(已在CSS中指定),以便水平滚动条发挥作用。

干杯!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

╭ゆ眷念 2024-10-22 11:14:54

您需要添加

white-space:nowrap;

浏览器似乎并不都同意此属性的继承,因此请尝试将其添加到两个 css 规则中。

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.

若言繁花未落 2024-10-22 11:14:54

您是否尝试过将 display:inline 添加到 a.pageLink 类中

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

醉南桥 2024-10-22 11:14:54

Overflow-x 可能不是最好的选择,因为我们仍在等待所有浏览器采用所有 CSS3 功能。

从用户体验的角度来看,您真的需要 13 个(或更多)分页结果吗?如果你决定是,那么我会考虑将你的分页结果放入一个列表中,并使用 css 声明 display:inline; 使 li 左浮动。

要强制您的列表始终显示在一行上,请考虑 white-space:nowrap

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

苏大泽ㄣ 2024-10-22 11:14:54

如果您对浏览器兼容性不挑剔:

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

我也打算建议 white-space: nowrap; 但 @Noel Walters 打败了我。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文