「小程序JAVA实战」 小程序wxss样式文件的使用(七)
转自:https://idig8.com/2018/08/09/xiaochengxu-chuji-07/
细说下微信小程序的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
/* pages/index/index.wxss */
.txt-test{
margin-top: 800rpx;
}

外部样式引入
新建一个跟现有的文件夹内的wxss名称不一样的,一个文件名称,然后import 引入外部的wxss,就可以在wxml使用了。通过@import 的方式引入到本身要引入的wxss里面,然后
/* pages/index/out.wxss */
.txt-left{
margin-left: 100rpx;
}
/* pages/index/index.wxss */
@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')
}
})
<!--index.wxml-->
<view class="container">
<text class="txt-test">{{motto}}</text>
<text class="txt-left">{{testoutcss}}</text>
</view>

样式关键字使用数据绑定的方式
样式里面也可以通过数据绑定的方式进行显示
//index.js
Page({
data: {
motto: '测试下数据绑定',
testoutcss: '测试外部css样式',
color:"red",
userInfo: {},
hasUserInfo: false,
canIUse: wx.canIUse('button.open-type.getUserInfo')
}
})
color绑定的方式
<!--index.wxml-->
<view class="container">
<text style="color:{{color}}">{{motto}}</text>
<text class="txt-test">{{motto}}</text>
<text class="txt-left">{{testoutcss}}</text>
</view>

全局样式和局部样式名称相同的选择
全局样式和局部样式名称相同时,按照局部的样式进行
- 定义全局txt-right进行演示
/**app.wxss**/
.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进行演示
/* pages/index/index.wxss */
@import "out.wxss";
.txt-test{
margin-top: 800rpx;
}
#txt-right{
margin-right: 300rpx;
color: black;
}
<!--index.wxml-->
<view class="container">
<text id="txt-right">{{globalcss}}</text>
<text style="color:{{color}}">{{motto}}</text>
<text class="txt-test">{{motto}}</text>
<text class="txt-left">{{testoutcss}}</text>
</view>

PS:样式这块比较依赖html中的css,明白如何引用,关联关系,style的方式自定义样式。
「小程序JAVA实战」 小程序wxss样式文件的使用(七)的更多相关文章
- 「小程序JAVA实战」小程序的flex布局(22)
转自:https://idig8.com/2018/08/09/xiaochengxu-chuji-22/ 之前已经把小程序的框架说完了,接下来说说小程序的组件,在说组件之前,先说说布局吧.源码:ht ...
- 「小程序JAVA实战」 小程序手写属于自己的第一个demo(六)
转自:https://idig8.com/2018/08/09/xiaochengxu-chuji-06/ 自己尝试的写一个小demo,用到自定义样式,自定义底部导航,页面之间的跳转等小功能.官方文档 ...
- 「小程序JAVA实战」小程序的留言和评价功能(70)
转自:https://idig8.com/2018/10/28/xiaochengxujavashizhanxiaochengxudeliuyanhepingjiagongneng69/ 目前小程序这 ...
- 「小程序JAVA实战」小程序的举报功能开发(68)
转自:https://idig8.com/2018/09/25/xiaochengxujavashizhanxiaochengxudeweixinapicaidancaozuo66-2/ 通过点击举报 ...
- 「小程序JAVA实战」小程序的个人信息作品,收藏,关注(66)
转自:https://idig8.com/2018/09/24/xiaochengxujavashizhanxiaochengxudegerenxinxizuopinshoucangguanzhu65 ...
- 「小程序JAVA实战」小程序的关注功能(65)
转自:https://idig8.com/2018/09/24/xiaochengxujavashizhanxiaochengxudeguanzhugongneng64/ 在个人页面,根据发布者个人和 ...
- 「小程序JAVA实战」小程序的视频点赞功能开发(62)
转自:https://idig8.com/2018/09/24/xiaochengxujavashizhanxiaochengxudeshipindianzangongnengkaifa61/ 视频点 ...
- 「小程序JAVA实战」小程序的springboot后台拦截器(61)
转自:https://idig8.com/2018/09/24/xiaochengxujavashizhanxiaochengxudespringboothoutailanjieqi60/ 之前咱们把 ...
- 「小程序JAVA实战」小程序首页视频(49)
转自:https://idig8.com/2018/09/21/xiaochengxujavashizhanxiaochengxushouyeshipin48/ 视频显示的内容是视频的截图,用户的头像 ...
随机推荐
- 【git】常用命令大全
Git常用操作命令收集: 1) 远程仓库相关命令 检出仓库:$ git clone git://github.com/jquery/jquery.git 后边接仓库文件地址 查看远程仓库:$ gi ...
- LeetCode OJ:Count Primes(质数计数)
Count the number of prime numbers less than a non-negative number, n. 计算小于n的质数的个数,当然就要用到大名鼎鼎的筛法了,代码如 ...
- Spring:org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class
很长时间没有使用Spring,Hibernate,Struts2等一些框架了,现在使用起来还是有点陌生,今天刚弄就在Tomcat在启动的时候是报的这个错误: org.springframework.b ...
- 【tensorflow:Google】三、tensorflow入门
[一]计算图模型 节点是计算,边是数据流, a = tf.constant( [1., 2.] )定义的是节点,节点有属性 a.graph 取得默认计算图 g1 = tf.get_default_gr ...
- 【PL/SQL编程】SQL与PL/SQL的区别
SQL概念: SQL是结构化查询语言,由数据定义语言.数据操纵语言.数据控制语言构成,它不面向过程,即前一条语句与后一条语句无关.它没有流程控制,也不存在变量. PL SQL概念: PL/SQL ...
- poj2378(dfs,树形dp)
和poj3107,poj1655一样的方法 #include<iostream> #include<cstdio> #include<cstdlib> #inclu ...
- 第一章 Linux系统入门
设定目标,寻求方法,勤奋努力,坚持不懈. ------你们知道了,而我们做到了.------ 世界上第一台计算机:ENIAC(埃尼亚克).1946-2 宾夕法尼亚大学. 约翰·冯·诺依曼体系 电脑的组 ...
- xcode加载静态链接库.a文件总是失败
明明项目是对的,代码没有问题,并且把项目作为库项目引入到新项目中没问题,可是一旦把项目编译出.a文件,引入到新项目中不知为何会有几率出现一大堆错误,其实是xcode的缓存机制在作怪,去这个目录: /U ...
- MySql必知必会实战练习(二)数据检索
在上篇博客MySql必知必会实战练习(一)表创建和数据添加中完成了各表的创建和数据添加,下面进行数据检索和过滤操作. 1. Select子句使用顺序 select--->DISTINCT---& ...
- 获取设备 ID 和名称
获取设备 ID 和名称 .NET Framework 3.5 其他版本 更新:2007 年 11 月 要获取设备的名称,请使用 Dns.GetHostName 属性.通常情况下,默认名称为“P ...