2.属性选择器
/*元素选择器*/
ul { padding: 0;margin: 0;width: 450px;border: 1px dashed #666;padding: 10px 5px;}ul:after { /*子块撑开父块*/content:''; /*在子元素尾部添加空内容元素*/display: block; /*并设置为块级显示*/clear:both; /*清除二边的浮动*/}li { list-style: none; /*去掉默认列表项样式*/float: left; /*左浮动*/width: 40px; /*设置宽度*/height: 40px; /*设置高度*/line-height: 40px; /*文本垂直居中*/text-align: center; /*文本水平居中*/border-radius: 50%; /*设置边框圆角*/background: skyblue; /*背景色天蓝*/margin-right: 5px; /*每个球之间的右外边距*/}
/*根据属性名来选择:例如id属性*/
*[id] { /*等价于: li[id]*//*background-color: red;*/}
/*根据属性名与值来选择:例如选择class=”green”的元素*/
li[class="green"] {/*background-color: lightgreen;*/}
/*选择class属性值中包括指定单词的元素*/
li[class ~= "red"] {background-color: brown;}
/*选择以’ph’字母开头的class类样式元素*/
立即学习“前端免费学习笔记(深入)”;
li[class ^= "ph"] {background-color: coral;}
/*选择以’s’结尾的类样式元素*/
li[class $= "s"] {background-color: lime; /*青绿*/}
/*选择属性值中包括指定字母’e’的类样式元素:;*/
li[class *= "e"] {background-color: yellowgreen; /*234背景为黄绿色*/}- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
以上就是css属性选择器实例的详细内容,更多请关注创想鸟其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/1610775.html
微信扫一扫
支付宝扫一扫