隐藏滚动条,移动端

1.原因

当然是滚动条长得丑才需要隐藏啊,真是开玩笑~~~QAQ而且也抵挡不住产品的吐槽,硬着头皮上了。

2. 方法

1.使用CSS3的transform:translate配合padding和margin使用。(只支持CSS3的浏览器,来自百度的方法。)
2.使用原生的position: realtive配合padding和margin使用。(我自己写的,测试无兼容性问题)
3. 举个栗子

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>隐藏横向滚动条</title>
    <style>
    * {
        margin: 0;
        padding: 0;
    }

    .cover {
        width: 100%;
        height: 60px;
        overflow: hidden;
    }

    .father {
        width: 100%;
        padding: 0 10px;
        background-color: #ff630c;
        overflow-x: auto;
        margin-top: -30px;
        padding-bottom: 30px;
        -webkit-transform: translateY(30px);
        transform: translateY(30px);
        box-sizing: border-box;
    }

    .son {
        width: 500%;
        letter-spacing: -10px;
    }

    .show {
        width: 19%;
        height: 60px;
        background-color: #f00;
        display: inline-block;
        *display: inline;
        *zoom: 1;
        margin-right: 5px;
        text-align: center;
    }

    .second {
        width: 100%;
        height: 50px;
        background-color: #eee;
        z-index: 100000;
    }
    </style>
    <style>
    .cover2 {
        width: 100%;
        height: 50px;
        overflow: hidden;
    }
    .father2 {
        box-sizing: border-box;
        overflow-x: scroll;
        width: 100%;
        position: relative;
        top: 30px;
        margin-top: -30px;
        padding-bottom: 30px;
        -webkit-overflow-scrolling: touch;
        opacity: 0.8;
    }

    .son2 {
        width: 500%;
    }

    .show2 {
        display: inline-block;
        vertical-align: middle;
        letter-spacing: -99999px;
        text-align: center;
        width: 19%;
        margin-right: 10px;
        height: 50px;
        background-color: #f00;
    }
    </style>
</head>

<body>
    <div class="cover">
        <div class="father">
            <div class="son">
                <div class="show">1</div>
                <div class="show">2</div>
                <div class="show">3</div>
                <div class="show">4</div>
                <div class="show">5</div>
            </div>
        </div>
    </div>
    <div class="cover">
        <div class="father2">
            <div class="son2">
                <div class="show2">1</div>
                <div class="show2">2</div>
                <div class="show2">3</div>
                <div class="show2">4</div>
                <div class="show2">5</div>
            </div>
        </div>
    </div>
    <div class="second"></div>
</body>

</html>

三、小结

还有点问题, 就是父级不应该设置高度的,我再找找解决方法。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值