找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 1702|回复: 0

[教程] CSS选择器学习笔记(2)

[复制链接]
发表于 2013-4-10 17:47:57 | 显示全部楼层 |阅读模式 来自 北京市
6 ID选择器:
[backcolor=rgb(255, 255, 255) !important]
[backcolor=rgb(255, 255, 255) !important]
1
#header{font-weight:bold;}



7 属性选择器:
1)
[backcolor=rgb(255, 255, 255) !important]
[backcolor=rgb(255, 255, 255) !important]
1
*[href]{color:red;}

[backcolor=rgb(248, 248, 248) !important]
2
<!-- lang: css -->

[backcolor=rgb(255, 255, 255) !important]
3

[backcolor=rgb(248, 248, 248) !important]
4
<!-- lang: css -->

[backcolor=rgb(255, 255, 255) !important]
5
    a[href][title]{font-weight:bold;}

[backcolor=rgb(248, 248, 248) !important]
6
<!-- lang: css -->

[backcolor=rgb(255, 255, 255) !important]
7

[backcolor=rgb(248, 248, 248) !important]
8
<!-- lang: css -->

[backcolor=rgb(255, 255, 255) !important]
9
    a[href="[color=blue !important]http://www.w3school.com.cn/"][title="W3School"] {color: red;}



2)
[backcolor=rgb(255, 255, 255) !important]
[backcolor=rgb(255, 255, 255) !important]
1
img[title~="Figure"] {border: 1px solid gray;}

[backcolor=rgb(248, 248, 248) !important]
2
<!-- lang: css -->

[backcolor=rgb(255, 255, 255) !important]
3
//这个规则会选择 title 文本包含 "Figure" 的所有图像。没有 title 属性或者 title 属性中不包含 "Figure" 的图像都不会匹配。

[backcolor=rgb(248, 248, 248) !important]
4

[backcolor=rgb(255, 255, 255) !important]
5
同理:



[abc^="def"]选择 abc 属性值以 "def" 开头的所有元素
[abc$="def"]选择 abc 属性值以 "def" 结尾的所有元素
[abc*="def"]选择 abc 属性值中包含子串 "def" 的所有元素
[backcolor=rgb(255, 255, 255) !important]
[backcolor=rgb(255, 255, 255) !important]
1
*[lang|="en"] {color: red;}



上面这个规则会选择 lang 属性等于 en 或以 en- 开头的所有元素。
8 后代选择器
1)
h1 em {color:red;} 上面这个规则会把作为 h1 元素后代的 em 元素的文本变为 红色。其他 em 文本(如段落或块引用中的 em)则不会被这个规则选中:
[backcolor=rgb(255, 255, 255) !important]
[backcolor=rgb(255, 255, 255) !important]
1
<h1>This is a <em>important</em> heading</h1>

[backcolor=rgb(248, 248, 248) !important]
2
<!-- lang: html -->

[backcolor=rgb(255, 255, 255) !important]
3
<p>This is a <em>important</em> paragraph.</p>

[backcolor=rgb(248, 248, 248) !important]
4

[backcolor=rgb(255, 255, 255) !important]
5
2)



如果您希望选择只作为 h1 元素子元素的 strong 元素,可以这样写:
[backcolor=rgb(255, 255, 255) !important]
[backcolor=rgb(255, 255, 255) !important]
1
h1 > strong {color:red;}



这个规则会把第一个 h1 下面的 strong 元素变为红色,但是第二个 strong 不受影响,第三个h1下的strong也变红:
[backcolor=rgb(255, 255, 255) !important]
[backcolor=rgb(255, 255, 255) !important]
1
<h1>This is <strong>very</strong> important.</h1>

[backcolor=rgb(248, 248, 248) !important]
2
<!-- lang: html -->

[backcolor=rgb(255, 255, 255) !important]
3
<h1>This is <em>really <strong>very</strong></em> important.</h1>

[backcolor=rgb(248, 248, 248) !important]
4
<!-- lang: html -->

[backcolor=rgb(255, 255, 255) !important]
5
<h1><strong>Hello</strong></h1>





发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;

如何回报帮助你解决问题的坛友,好办法就是点击帖子下方的评分按钮给对方加【金币】不会扣除自己的积分,做一个热心并受欢迎的人!

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则 需要先绑定手机号

关闭

站长推荐上一条 /1 下一条

QQ|侵权投诉|广告报价|手机版|小黑屋|西部数码代理|飘仙建站论坛 ( 豫ICP备2022021143号-1 )

GMT+8, 2024-5-9 06:50 , Processed in 0.040627 second(s), 9 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表