--- title: 'Test your skills: Selectors' slug: Learn/CSS/Building_blocks/Selectors/Selectors_Tasks translation_of: Learn/CSS/Building_blocks/Selectors/Selectors_Tasks ---
这个任务的目的是帮助你理解CSS里的选择器。
Note:你可以 在下面那些交换编辑器中尝试解决问题,然而 把代码下载然后使用一个在线工具比如 CodePen, jsFiddle, or Glitch 去解决这些问题可能对你更有作用。
如果你卡住了,可以向我们寻求帮助 — 请参阅本页底部的Assessment or further help 部分。
在没有改变HTML的情况下,使用CSS去完成下面的要求::
Try updating the live code below to recreate the finished example:
{{EmbedGHLiveSample("css-examples/learn/tasks/selectors/type.html", '100%', 700)}}
For assessment or further work purposes, download the starting point for this task to work in your own editor or in an online editor.
在没有改变HTML的情况下,对本例中内容的外观进行以下更改:
special
的元素有一个黄色背景。alert
的元素有一个 1px 的灰色边框。alert
类还有 stop
类, 让它的背景变为红色。alert
类还有 go
类,让它的背景变为绿色。Try updating the live code below to recreate the finished example:
{{EmbedGHLiveSample("css-examples/learn/tasks/selectors/class-id.html", '100%', 800)}}
For assessment or further work purposes, download the starting point for this task to work in your own editor or in an online editor.
在本例中,尝试在不添加HTML的情况下进行以下更改。
Try updating the live code below to recreate the finished example:
{{EmbedGHLiveSample("css-examples/learn/tasks/selectors/pseudo.html", '100%', 800)}}
For assessment or further work purposes, download the starting point for this task to work in your own editor or in an online editor.
在这个任务中尝试下面这个任务:
Try updating the live code below to recreate the finished example:
{{EmbedGHLiveSample("css-examples/learn/tasks/selectors/combinators.html", '100%', 800)}}
For assessment or further work purposes, download the starting point for this task to work in your own editor or in an online editor.
在最后一个任务中,使用属性选择器添加CSS以执行以下操作:
<a>
element with a title
attribute and make the border pink (border-color: pink
).<a>
element with an href
attribute that contains the word contact
somewhere in its value and make the border orange (border-color: orange
).<a>
element with an href
value starting with https
and give it a green border (border-color: green
).Try updating the live code below to recreate the finished example:
{{EmbedGHLiveSample("css-examples/learn/tasks/selectors/attribute-links.html", '100%', 800)}}
For assessment or further work purposes, download the starting point for this task to work in your own editor or in an online editor.
You can practice these examples in the Interactive Editors mentioned above.
If you would like your work assessed, or are stuck and want to ask for help: