栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java > SpringBoot

「小程序JAVA实战」 小程序wxss样式文件的使用(七)

SpringBoot 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

「小程序JAVA实战」 小程序wxss样式文件的使用(七)

细说下微信小程序的wxss样式文件。源码:https://github.com/limingios/wxProgram.git 中的No.2

样式rpx

原来在html里面都是使用px和pt,微信这边自定义的rpx的方式。
文档:https://developers.weixin.qq.com/miniprogram/dev/framework/view/wxss.html

.txt-test{
  margin-top: 800rpx;
}

外部样式引入

新建一个跟现有的文件夹内的wxss名称不一样的,一个文件名称,然后import 引入外部的wxss,就可以在wxml使用了。通过@import 的方式引入到本身要引入的wxss里面,然后

.txt-left{
  margin-left: 100rpx;
}
@import "out.wxss";

.txt-test{
  margin-top: 800rpx;
}
//index.js
Page({
  data: {
    motto: '测试下数据绑定',
    testoutcss: '测试外部css样式',
    userInfo: {},
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo')
  }
})

  {{motto}}
  {{testoutcss}}

样式关键字使用数据绑定的方式

样式里面也可以通过数据绑定的方式进行显示

//index.js
Page({
  data: {
    motto: '测试下数据绑定',
    testoutcss: '测试外部css样式',
    color:"red",
    userInfo: {},
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo')
  }
})

color绑定的方式


  {{motto}}   
  {{motto}}
  {{testoutcss}}

全局样式和局部样式名称相同的选择

全局样式和局部样式名称相同时,按照局部的样式进行

  • 定义全局txt-right进行演示

.container {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 200rpx 0;
  box-sizing: border-box;
} 

#txt-right{
  margin-right: 100rpx;
  color: yellow;
}
  • 定义局部txt-right进行演示

@import "out.wxss";

.txt-test{
  margin-top: 800rpx;
}

#txt-right{
  margin-right: 300rpx;
  color: black;
}

  {{globalcss}} 
  {{motto}}   
  {{motto}}
  {{testoutcss}}

PS:样式这块比较依赖html中的css,明白如何引用,关联关系,style的方式自定义样式。


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/234980.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号