CSS水平滚动(简单)
鉴于:
<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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您需要添加
浏览器似乎并不都同意此属性的继承,因此请尝试将其添加到两个 css 规则中。
you need to add
Browsers don't all seem to agree about inheritance on this attribute so try adding it to both css rules.
您是否尝试过将 display:inline 添加到 a.pageLink 类中
have you tried adding display:inline to the a.pageLink class
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
如果您对浏览器兼容性不挑剔:
我也打算建议
white-space: nowrap;
但 @Noel Walters 打败了我。If you're not picky about browser compatibility:
and I was going to suggest
white-space: nowrap;
as well but @Noel Walters beat me to it.