[CSS3] Make a horizontal-scrolling Menu

本文介绍了一种在小屏幕设备上保持导航菜单宽度的同时,确保其可用性的方法。通过使用水平滚动的方式,即使在屏幕尺寸受限的情况下也能保持菜单项的完整性,并提供平滑的滚动体验。


Our web app on desktop may use elements that use great deal of width. On many occasions we can’t simply turn these elements into columns so that they fit on a small screen. Such elements may not only fit inadequately on small screens, they could ruin the entire layout of our page if we’re not careful. In many cases, we can use a horizontal-scrolling menu to preserve the width, but keep it easily usable.

 

  <nav>
    <a href="">Home</a>
    <a href="">My Profile</a>
    <a href="">Favorites</a>
    <a href="">Links</a>
    <a href="">Tasks</a>
    <a href="">Promotions</a>
    <a href="">Settings</a>
  </nav>
nav {
  display: flex;
  overflow-x: auto; /*Allow children in nav can overflow in x direction*/
  -webkit-overflow-scrolling: touch; /*Let the scroll more smoothing*/
  margin: 10px 0;
}

a {
  margin-right: 20px;
  margin-bottom: 10px;
  white-space: nowrap;
}

 

转载于:https://www.cnblogs.com/Answer1215/p/9192502.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值