flex布局下横纵向布局下--横向滚动

本文探讨了如何在Flex布局中实现横纵向滚动效果,详细解析了相关CSS属性的使用,帮助开发者创建灵活多样的布局解决方案。
<!doctype html>
<html>
<head>
    <meta charset="utf-8">
</head>
<body>
<div class="o-box">
    <div class="l-box"></div>
    <div class="m-box">
        <div class="content"></div>
        <div class="wrapper">
            <div class="item"></div>
            <div class="item"></div>
            <div class="item"></div>
            <div class="item"></div>
            <div class="item"></div>
            <div class="item"></div>
            <div class="item"></div>
            <div class="item"></div>
            <div class="item"></div>
            <div class="item"></div>
            <div class="item"></div>
            <div class="item"></div>
            <div class="item"></div>
            <div class="item"></div>
            <div class="item"></div>
            <div class="item"></div>
            <div class="item"></div>
            <div class="item"></div>
        </div>
    </div>
    <div class="r-box"></div>
</div>

<style>
    * {
        margin: 0;
        padding: 0
    }

    body {
        width: 100%;
        height: 100vh;
        display: flex;
        overflow: hidden;
    }

    .o-box {
        width: 100%;
        height: 100%;
        flex: 1;
        display: flex;
        flex-direction: row;
    }

    .l-box {
        width: 180px;
        border: solid 1px #dddddd;
    }

    .m-box {
        flex: 1;
        display: flex;
        border: solid 1px #dddddd;
        flex-direction: column;
        overflow: hidden;
    }

    .r-box {
        width: 180px;
        border: solid 1px #dddddd;
    }

    .content {
        flex: 1;
    }

    .wrapper {
        width: 100%;
        display: flex;
        overflow-x: scroll;
        border: 1px solid #f00;
    }

    .item {
        height: 100px;
        width: 100px;
        background-color: #f00;
        margin: 10px;
        flex-shrink: 0;
    }

    .wrapper::-webkit-scrollbar {
        width: 1px;
        height: 6px;
    }

    .wrapper::-webkit-scrollbar-thumb {
        border-radius: 10px;
        box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.5);
        background: #ccc;
    }

    .wrapper::-webkit-scrollbar-track {
        box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
        border-radius: 10px;
        background: #ededed;
    }
</style>
</body>
</html>

<script setup lang="ts"> definePage({ name: 'home', layout: 'tabbar', style: { navigationBarTitleText: '首页', navigationStyle: 'custom', disableScroll: true, // 关键:隐藏滚动条,启用沉浸式 'app-plus': {scrollIndicator: 'none'} }, }) const current = ref<number>(0) const swiperList = ref([ 'https://wot-ui.cn/assets/redpanda.jpg', 'https://wot-ui.cn/assets/capybara.jpg', 'https://wot-ui.cn/assets/panda.jpg', 'https://wot-ui.cn/assets/moon.jpg', 'https://wot-ui.cn/assets/meng.jpg' ]) const listData = ref([ {id: 1, url: '/static/domain.png', name: '领券中心'}, {id: 2, url: '/static/domain.png', name: '签到好礼'}, {id: 3, url: '/static/domain.png', name: '新人攻略'}, {id: 4, url: '/static/domain.png', name: '进群福利'}, {id: 5, url: '/static/domain.png', name: '自助服务'} ]) function handleClick(e) { console.log(e) } function onChange(e) { console.log(e) } </script> <template> <view class="container"> <scroll-view class="scroll-container" :scroll-x="true"> <view class="top-box"> <view class="top-box-1"> </view> <view class="card-swiper"> <wd-swiper autoplay v-model:current="current" custom-indicator-class="custom-indicator-class" custom-image-class="custom-image" custom-class="custom-swiper" custom-next-image-class="custom-image-prev" custom-prev-image-class="custom-image-prev" height="800rpx" :indicator="{ type: 'dots' }" :list="swiperList" previousMargin="24px" nextMargin="24px" @click="handleClick" ></wd-swiper> </view> </view> <view class="center-box"> <!-- 横向滚动区域 --> <scroll-view class="scroll-view" :scroll-x="true" :show-scrollbar="false"> <view class="item-list"> <view class="item" v-for="(item, index) in listData" :key="index"> <image :src="item.url" class="item-image"></image> <text class="item-text">{{ item.name }}</text> </view> </view> </scroll-view> </view> <view class="bottom-box"> </view> </scroll-view> </view> </template> <style scoped lang="scss"> .scroll-container { height: 100%; } .top-box { .top-box-1 { height: 300rpx; background: #cc71f6; } } .card-swiper { height: 800rpx; width: 100%; position: relative; bottom: 100rpx; box-sizing: border-box; --wot-swiper-radius: 0; --wot-swiper-item-padding: 0 24rpx; --wot-swiper-nav-dot-color: #e7e7e7; --wot-swiper-nav-dot-active-color: #4d80f0; padding-bottom: 24rpx; :deep(.custom-indicator-class) { bottom: -16px; } :deep(.custom-swiper) { height: 800rpx !important; } :deep(.custom-image) { border-radius: 18rpx !important; } :deep(.custom-image-prev) { height: 720rpx !important; border-radius: 12rpx !important; } } .center-box { height: 100rpx; .scroll-view { white-space: nowrap; width: 100%; border-radius: 12rpx; overflow: hidden; .item-list { display: flex; margin: 0 23rpx; gap: 23rpx; .item { flex-shrink: 0; /* 关键:防止压缩 */ width: 170rpx; height: 180rpx; display: inline-flex; flex-direction: column; border-radius: 16rpx; align-items: center; justify-content: center; .item-text { margin-top: 15rpx; color: #595959; font-weight: 600; font-size: 26rpx; } .item-image { height: 90rpx; width: 90rpx; } } } } } .bottom-box { height: 600rpx; border-radius: 18rpx; background: #007aff; } </style> 不能上下滑动
最新发布
12-23
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值