uniapp样式选择器最全详解

转自 duanshuilu.com

 

具体支持情况见下表(Y表示支持,N表示不支持)

选择器 css版本 h5 安卓 ios 微信小程序 备注
.class css1 Y Y Y Y -
#id css1 Y Y Y Y -
* css2 Y N N N -
element css1 Y Y Y Y 注意类似于html,body这样的选择器,
非h5端会被转成page
element,element css1 Y Y Y Y -
element>element css2 Y Y Y Y -
element+element css2 Y Y Y Y -
[attribute] css2 Y Y Y Y 1.h5端使用uniapp标签属性时,
编译后该属性可能会消失,
导致该选择器"失效",
如,viewhover-class属性
2.微信小程序/app端使用非规范
的属性,如,
<view qwe-rt="asd"></view>
在编译到微信小程序/app时会消失
同样导致该选择器"失效"
[attribute=value] css2 Y Y Y Y [attribute]
[attribute~=value] css2 Y Y Y Y [attribute]
[attribute|=value] css2 Y Y Y Y [attribute]
:link css1 Y - - - 没有找到办法在非h5上
生成a标签
:visited css1 Y - - - 没有找到办法在非h5上
生成a标签
:active css1 Y Y Y Y 在非h5的其他三端上表现
<view hover-class="xxx">属性一致
(只测试了view标签与text标签)
:hover css1 Y Y Y Y 表现基本同:active
但是要取消该状态
是要点击其他标签
(让hover转移到其他标签上)
:focus css2 N N N N 1.h5中会把<input />编译成一个
uni-input>div>input+div.input-placeholder的结构,
在css代码中写的类似于
input:focus{background: #F00;}的样式,
基本上是设置在uni-input这个标签上的,
所以期望input的focus样式并不会出现
(所以h5是因为uni-app对
css代码的编译逻辑
导致不支持input的:focus选择器)
2.类似于button这些本来在正常html标签中
是能在点击时获得focus状态的
但在uniapp中,h5会编译成uni-button标签,
这些标签没发现它能在点击后获得focus状态
3.其他三端虽然没像如上描述那样转,
(直接转成一个input._input,button._button)
但是却不支持focus状态
不知道是不是官方(dcloud/微信)故意的
:first-letter css1 Y Y Y Y 注意别踩坑
:first-line css1 Y Y Y Y 注意别踩坑
:first-child css2 Y Y Y Y -
:before css2 Y Y Y Y -
:after css2 Y Y Y Y -
:lang(language) css2 Y N N N -
element1~element2 css3 Y Y Y Y -
[attribute^=value] css3 Y Y Y Y [attribute]
[attribute$=value] css3 Y Y Y Y [attribute]
[attribute*=value] css3 Y Y Y Y [attribute]
:first-of-type css3 Y Y Y Y -
:last-of-type css3 Y Y Y Y -
:only-child css3 Y Y Y Y -
:nth-child(n) css3 Y Y Y Y -
:nth-last-child(n) css3 Y Y Y Y -
:nth-of-type(n) css3 Y Y Y Y -
:nth-last-of-type(n) css3 Y Y Y Y -
:last-child css3 Y Y Y Y -
:root css3 Y N N N h5端的支持只能是
在app.vue的style标签里写的
或者@import的样式里才能用:root
:empty css3 Y Y Y Y -
:target css3 Y - - - 没有找到办法在非h5上
实现锚点
:enabled css3 N N N N 类似于:focus,
可使用类似于
button:not([disabled])
的方案代替
:disabled css3 N N N N 类似于:focus,
但是可以使用类似于
button[disabled]
的方案代替
但是只写button[disabled]
权重可能不够
h5端写input[disabled]无效,
原因见:focus备注
但是非h5端可以写input[disabled]
:checked css3 N N N N :disabled
:not(selector) css3 Y Y Y Y -
::selection css3 Y Y N ios:N
安卓:Y
-

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章