移动端 网易云 左右滚动导航栏

移动端 网易云 左右滚动导航栏

先看效果

在这里插入图片描述

这边用vue演示:

方法一:

display: flex;
overflow-y: auto;  /*overflow-y: scroll/hiddle;也行*/

利用flex和overflow-y可以帮我们实现左右滚动,但是有滚动条

在这里插入图片描述

利用伪对象选择器,实现隐藏

ul::-webkit-scrollbar {
    display: none;
}

flex布局在横向排列时,子元素的宽度会失效,这时,可以给子元素通过下面的属性固定宽度。

flex: 0 0 50px; /* 设置固定宽度 */

完整代码

<template>
  <ul>
    <li>1</li>
    <li>2</li>
    <li>3</li>
    <li>4</li>
    <li>5</li>
    <li>6</li>
    <li>7</li>
    <li>8</li>
    <li>9</li>
</ul>
</template>

<script>
export default {

}
</script>

<style lang="less" scoped>
* {
        margin: 0;
        padding: 0;
    }
    ul {
        background: gold;
        display: flex;
        overflow-y: auto;
    }

    ul::-webkit-scrollbar {
        display: none;
    }

    ul li {
        /* width: 50px;设置了也不生效 */
        height: 30px;
        background: tomato;
        margin: 10px;
        list-style: none;        
        flex: 0 0 50px; /* 设置固定宽度 */
    }
</style>

方法二:

先把子元素变成内联块,让子元素自动在父容器中横排列

display: inline-block;

在父容器添加让子元素不换行,可以滚动

white-space: nowrap;
overflow-y: auto;

这个方法同样会出现滚动条,同样利用隐藏

ul::-webkit-scrollbar {
    display: none;
}

完整代码

<template>
  <ul>
    <li>1</li>
    <li>2</li>
    <li>3</li>
    <li>4</li>
    <li>5</li>
    <li>6</li>
    <li>7</li>
</ul>
</template>

<script>
export default {

}
</script>

<style lang="less" scoped>
	*{margin: 0;padding: 0;}
	ul{
	    background: pink;
	    white-space: nowrap;
	    overflow-y: auto;
	    /* -webkit-overflow-scrolling: touch;添加手滑模式touch  */
	}
	ul li{
	    width: 50px;
	    height: 30px;
	    background: yellow;
	    margin:10px;
	    list-style: none;
	    display: inline-block;
	}
</style>
  • 1
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

周粥粥ya

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值