博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
css 选择器 伪元素_CSS伪元素-解释选择器之前和之后
阅读量:2534 次
发布时间:2019-05-11

本文共 2188 字,大约阅读时间需要 7 分钟。

css 选择器 伪元素

选择器之前 (Before Selector)

The CSS ::before selector can be used to insert content before the content of the selected element or elements. It is used by attaching ::before to the element it is to be used on.

CSS ::before选择器可用于在选定元素或多个元素的内容之前插入内容。 通过将::before附加到要使用的元素上来使用它。

Let’s look at some examples:

让我们看一些例子:

p::before {   content: "* ";}span.comment::before {  content: "Comment: ";  color: blue;}

To infinity, and beyond!

I am Buzz Lightyear. I come in peace.

May the force be with you.
Do. Or do not. There is no try.

In the example above we are prepending an asterisk and a space before every paragraph element on the page. Also, we're prepending "Comment: " in blue before every span element with the class comment.

在上面的示例中,我们在页面上每个段落元素之前加一个星号和一个空格。 另外,我们在每个span元素之前,在带有class comment蓝色前添加“ Comment:”。

选择器之后 (After Selector)

The CSS ::after selector can be used to insert content after the content of the selected element or elements. It's used by attaching ::after to the element it is to be used on.

CSS ::after选择器可用于在一个或多个选定元素的内容之后插入内容。 通过将::after附加到要使用的元素上来使用。

Here are some examples:

这里有些例子:

.buzz::after {   content: " - Buzz Lightyear";  color: blue;}.yoda::after {   content: " - Yoda";  color: green;}

To infinity, and beyond!

Do. Or do not. There is no try.

In the example above, we're appending " - Buzz Lightyear" in blue to the element with the class buzz. Also, we're appending " - Yoda" in green to the element with the class yoda.

在上面的示例中,我们将蓝色的“-Buzz Lightyear”附加到具有buzz类的元素上。 另外,我们在类yoda的元素后面添加绿色的“ yoda

单冒号与双冒号 (Single-colon vs. Double-colon)

There’s a bit of discussion about the right way of using pseudo-elements – the old style single-colon (:before), used in CSS specifications 1 and 2, versus the CSS3 recommendation, double-colon (::before), mainly to “establish a discrimination between pseudo-classes and pseudo-elements”.

关于使用伪元素的正确方法,有一些讨论– CSS规范1和2中使用的旧样式单冒号( :before )与CSS3建议双冒号( ::before ),主要是为了“在伪类和伪元素之间建立区分”

But for compatibility reasons, the single-colon method is still accepted. Keep in mind that IE8 supports the single-colon notation only.

但是出于兼容性原因,单冒号方法仍然被接受。 请记住,IE8仅支持单冒号表示法。

更多信息: (More Information:)

翻译自:

css 选择器 伪元素

转载地址:http://cduzd.baihongyu.com/

你可能感兴趣的文章
面向对象编程思想概览(四)多线程
查看>>
二十三种设计模式及其python实现
查看>>
Math类、Random类、System类、BigInteger类、BigDecimal类、Date类、SimpleDateFormat、Calendar类...
查看>>
【设计模式】 访问者模式
查看>>
关于FFMPEG 中I帧、B帧、P帧、PTS、DTS
查看>>
request和response的知识
查看>>
bootstrap 表单类
查看>>
20165332第四周学习总结
查看>>
Codeforces Round #200 (Div. 1)D. Water Tree dfs序
查看>>
linux安全设置
查看>>
Myflight航班查询系统
查看>>
团队-团队编程项目爬取豆瓣电影top250-代码设计规范
查看>>
【linux驱动分析】之dm9000驱动分析(六):dm9000_init和dm9000_probe的实现
查看>>
json具体解释
查看>>
十一:Java之GUI图形Awt和Swing
查看>>
.net在arraylist用法
查看>>
android程序报错“error launching activity com.android.ddmlib.shellcommandunresponsiveexception”的解决方式...
查看>>
ORACLE中CONSTRAINT的四对属性
查看>>
DbVisualizer Pro 9.5.2中文乱码问题
查看>>
numpy.tile()
查看>>