微信小程序1——scroll-x和scroll-y的用法

  1. scroll-x横向滑动
  2. scroll-y纵向滑动

1.scroll-x允许横向滑动,首先在list-wxml中加入下列代码

<scroll-view class="container1" scroll-x>
<view>A</view>
<view>B</view>
<view>C</view>
</scroll-view>
<!--scroll-y 允许纵向滚动
scroll-x 允许横向滚动-->

在这里插入图片描述

打开list-wxss,加入下列代码
.container1 view {
  display: inline-block; 
  // 设置 display 属性为 inline-block,这会使元素以内联块级元素的方式显示,可以在同一行内显示多个元素
    height: 100px;
    text-align: center;
    width: 100px;  
}
.container1 view:nth-child(1) {
    background-color: cornflowerblue;
}
.container1 view:nth-child(2) {
  background-color: lightblue;
}
.container1 view:nth-child(3) {
  background-color: lightcoral;
}
.container1 {
  border: 1px solid red;
  height: 100px;
  width: 120px; 
  white-space: nowrap;
    // 设置 white-space 属性为 nowrap,这会导致文本不换行,适合横向滚动的布局
  /*  display: flex;
  justify-content: space-around;
  第一次
  */
} 

2.scroll-y 允许纵向滑动,在list-wxml中加入下列代码

<scroll-view class="container1" scroll-y>
<view>A</view>
<view>B</view>
<view>C</view>
</scroll-view>
<!--scroll-y 允许纵向滚动
scroll-x 允许横向滚动-->

在list-wxss中加入下列代码:

.container1 view {
    height: 100px;
    width: 100px;
    text-align: center;
    line-height: 100px;
}
.container1 view:nth-child(1) {
    background-color: cornflowerblue;
}
.container1 view:nth-child(2) {
  background-color: lightblue;
}
.container1 view:nth-child(3) {
  background-color: lightcoral;
}
.container1 {
  border: 1px solid red;
  height: 120px;
  width: 100px; 
  /*  display: flex;
  justify-content: space-around;
  第一次
  */
} 

成果展示:
在这里插入图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值