Attribute Selectors

本文记录了一次使用CSS属性选择器解决网页多个相同名称div元素边框统一设置的问题。作者试图通过div[name=aaa]的方式直接在CSS中进行样式设置,但遇到了HTML文档类型声明缺失及脚本执行时机的问题。

  今天碰到个问题,有很多页面里面包含了同样一个div,可是这个东西当时只加了id用于操作(各不相同),还有一个name,这个所有div的值都一样,现在要为所有这样的div都加一个边框,实在是太烦恼的事情了。

  我很没心情去一个一个替换,所以打算在公共的CSS里面写个东西搞定,但是不知道怎么选name,嗯,这个时候突然想起来CSS里面有个Attribute Selector,可以通过指定某元素的属性来设置样式,所以我就写啦:

div[name="aaa"] {
border
: 1px solid #808080;
}

  哎,结果不起作用哈,我就纳闷坏了,我的测试文件明明是可以的哎,怎么搞的?后来碰巧发现,我测试的html文件里面有<!doctype html>,而大量存在的页面都是没得的,郁闷,这下没戏了。

  然后我又尝试在公共script文件里面去改,用document.getElementsByName去取得这些div,再设置它们的样式,又发现公共script都被包含在页面的head里面,这个时候文档都没加载完全呢……

  没办法,不理了,搁置搁置。

  今天的好运气是又回忆起来了这个属性选择,这样的写法,在有时候会很有用的,谁让我们的文档格式不标准呢。

wx.getSystemInfoSync is deprecated.Please use wx.getSystemSetting/wx.getAppAuthorizeSetting/wx.getDeviceInfo/wx.getWindowInfo/wx.getAppBaseInfo instead. (anonymous) @ uni.api.esm.js:882 sys @ index.js? [sm]:55 contentStyle @ uv-toast.vue:131 ComputedRefImpl.effect.computed @ vue.runtime.esm.js:986 run @ vue.runtime.esm.js:180 get @ vue.runtime.esm.js:998 get @ vue.runtime.esm.js:2991 _sfc_render @ uv-toast.vue:235 renderComponentRoot @ vue.runtime.esm.js:4966 componentUpdateFn @ vue.runtime.esm.js:5072 run @ vue.runtime.esm.js:180 instance.update @ vue.runtime.esm.js:5117 setupRenderEffect @ vue.runtime.esm.js:5128 mountComponent @ vue.runtime.esm.js:4911 createComponent22 @ vue.runtime.esm.js:5191 $createComponent @ uni.mp.esm.js:754 attached @ uni.mp.esm.js:871 11[pages/read/read] Some selectors are not allowed in component wxss, including tag name selectors, ID selectors, and attribute selectors.(.<URL>:1) [pages/read/read] Some selectors are not allowed in component wxss, including tag name selectors, ID selectors, and attribute selectors.(./uni_modules/uv-tags/components/uv-tags/uv-tags.wxss:26:1) [pages/read/read] Some selectors are not allowed in component wxss, including tag name selectors, ID selectors, and attribute selectors.(./uni_modules/uv-button/components/uv-button/uv-button.wxss:36:1) [pages/read/read] Some selectors are not allowed in component wxss, including tag name selectors, ID selectors, and attribute selectors.(./uni_modules/uv-toast/components/uv-toast/uv-toast.wxss:26:1) [pages/read/read] Some selectors are not allowed in component wxss, including tag name selectors, ID selectors, and attribute selectors.(./uni_modules/uv-list/components/uv-list/uv-list.wxss:26:1) [pages/read/read] Some selectors are not allowed in component wxss, including tag name selectors, ID selectors, and attribute selectors.(./uni_modules/uv-loading-icon/components/uv-loading-icon/uv-loading-icon.wxss:26:1) [pages/read/read] Some selectors are not allowed in component wxss, including tag name selectors, ID selectors, and attribute selectors.(./uni_modules/uv-switch/components/uv-switch/uv-switch.wxss:26:1) [pages/read/read] Some selectors are not allowed in component wxss, including tag name selectors, ID selectors, and attribute selectors.(./uni_modules/uv-badge/components/uv-badge/uv-badge.wxss:26:1) [pages/read/read] Some selectors are not allowed in component wxss, including tag name selectors, ID selectors, and attribute selectors.(./uni_modules/uv-list/components/uv-list-item/uv-list-item.wxss:66:1) [pages/read/read] Some selectors are not allowed in component wxss, including tag name selectors, ID selectors, and attribute selectors.(./uni_modules/uv-link/components/uv-link/uv-link.wxss:26:1) [pages/read/read] Some selectors are not allowed in component wxss, including tag name selectors, ID selectors, and attribute selectors.(./uni_modules/uv-icon/components/uv-icon/uv-icon.wxss:26:1) [pages/read/read] Some selectors are not allowed in component wxss, including tag name selectors, ID selectors, and attribute selectors.(./uni_modules/uv-text/components/uv-text/uv-text.wxss:76:1) [Violation] 'setTimeout' handler took 270ms [WXML Runtime warning] ./uni_modules/nx-reader/components/nx-reader/components/nx-reader-rich-text.wxml Now you can provide attr `wx:key` for a `wx:for` to improve performance. > 1 | <view><block wx:for="{{a}}" wx:for-item="n"><text wx:if="{{n.a}}" selectable="{{false}}" decode>{{n.b}}</text><text wx:elif="{{n.c}}" selectable="{{false}}">\n</text><rich-text wx:else nodes="{{n.d}}" selectable="{{false}}"></rich-text></block></view>小程序页面渲染不出来
最新发布
06-27
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值