content - 对象前或后显示内容 - css 文本样式
content
CSS的 content 属性用于在元素的::before
和::after
伪元素中插入内容。使用content
属性插入的内容都是匿名的可替换元素。
示例
content: normal /* Keywords that cannot be combined with other values */ content: none content: 'prefix' /* value, non-latin characters must be encoded e.g. \00A0 for */ content: url(http://www.example.com/test.html) /* value */ content: chapter_counter /* values */ content: attr(value string) /* attr() value linked to the HTML attribute value */ content: open-quote /* Language- and position-dependant keywords */ content: close-quote content: no-open-quote content: no-close-quote content: open-quote chapter_counter /* Except for normal and none, several values can be used simultaneously */ content: inherit
浏览器支持
IE8以上浏览器都支持content |
语法:
content:normal| none|:取值[pending()| | contents | footnote | endnote | div-note | list-item || | open-quote | close-quote | no-open-quote | no-close-quote | icon || | | document-url |]
=counter(name)| counter(name,list-style-type)| counters(name,string)| counters(name,string,list-style-type)
取值:
- none:不会产生伪类元素
- normal:在
:before
和:after
伪类元素中会被视为none
- :文本内容
- :
url()
URI值会指定一个外部资源(比如图片)。如果该资源或图片不能显示,它就会被忽略或显示一些占位(比如无图片标志)。 - :计数器可以指定两种不同的函数:
counter()
或counters()
。前面一个有两种形式:counter(name)
或counter(name,style)
。产生的内容是该伪类元素指定名称的最小范围的计数;格式由style指定(默认是'decimal'——十进制数字)。后一个函数同样也有两种形式:counters(name,string)
或counters(name,string,style)
。The generated text is the value of all counters with the given name in scope at this pseudo-element, from outermost to innermost separated by the specified string. The counters are rendered in the indicated style('decimal' by default). See the section on automatic counters and numbering for more information. The name must not be 'none','inherit' or 'initial'. Such a name causes the declaration to be ignored. attr(X)
将元素的X属性以字符串形式返回。如果该元素没有 X 属性,则返回一个空字符串。区分大小写的属性返回值依赖文挡的语言设定。open-quote
|close-quote
这些值会被quotes
中定义的字符串替换。no-open-quote
|no-close-quote
不会生产任何内容,但是会改变(增加或降低)引号层级。
例子
5
we shall start this with a quote from sir tim berners-lee, i was lucky enough to invent the web at the time when the internet already existed - and had for a decade and a half. we must understand that there is nothing fundamentally wrong with building on the contributions of others.
6
here we shall quote the mozilla manifesto, individuals must have the ability to shape the internet and their own experiences on the internet. and so, we can infer that contributing to the open web, can protect our own individual experiences on it.
//CSS q { color: #ff6600; font-style: italic; } q::before { content: open-quote } q::after { content: close-quote } h1::before { content: "chapter "; }
5
we shall start this with a quote from sir tim berners-lee, i was lucky enough to invent the web at the time when the internet already existed - and had for a decade and a half. we must understand that there is nothing fundamentally wrong with building on the contributions of others.
6
here we shall quote the mozilla manifesto, individuals must have the ability to shape the internet and their own experiences on the internet. and so, we can infer that contributing to the open web, can protect our own individual experiences on it.
.demo1 q{color:#ff6600; font-style: italic;}.demo1 q::before{content: open-quote}.demo1 q::after{content: close-quote}.demo1 h1::before{content:"chapter ";}代码举例- link前面加一个icon
home page //CSS a::before{ content: url(https://www.baikegou.com/favicon.ico) " qq344225443: "; font: x-small arial,freesans,sans-serif; color: gray; }
- this is my first idea
- and another good idea
CSS
/* first import the icon from a suitable site */ @import url(http://weloveiconfonts.com/api/?family=entypo); .brightidea li::after{ content: '1f4a1'; font-family: 'entypo', sans-serif; }
paperback best sellers
//CSS .newentry::after { content: " new!"; color: red; }
- political thriller
- halloween stories
- my biography
- vampire romance
- mozilla home page
- mozilla developer network
- world wide web consortium
鹏仔微信 15129739599 鹏仔QQ344225443 鹏仔前端 pjxi.com 共享博客 sharedbk.com
图片声明:本站部分配图来自网络。本站只作为美观性配图使用,无任何非法侵犯第三方意图,一切解释权归图片著作权方,本站不承担任何责任。如有恶意碰瓷者,必当奉陪到底严惩不贷!