content
åºçº¿
广æ³å¯ç¨
*
èª 2015å¹´7æ èµ·ï¼æ¤ç¹æ§å·²å¨ä¸»æµæµè§å¨ä¸å¾å°æ¯æï¼å¯å¨å¤§å¤æ°è®¾å¤åæµè§å¨çæ¬ä¸æ£å¸¸ä½¿ç¨ã
* æ¤ç¹æ§çæäºé¨åçæ¯æç¨åº¦å¯è½ææä¸åã
CSS ç content CSS 屿§ç¨äºå¨å
ç´ ç ::before å ::after 伪å
ç´ ä¸æå
¥å
容ãä½¿ç¨ content 屿§æå
¥çå
容齿¯å¿åç*坿¿æ¢å
ç´ *ã
è¯æ³
/* ä¸è½ä¸å
¶ä»å¼ç»åçå
³é®å */
content: normal;
content: none;
/* <content-replacement>ï¼<image> å¼ */
content: url("http://www.example.com/test.png");
content: linear-gradient(#e66465, #9198e5);
content: image-set("image1x.png" 1x, "image2x.png" 2x);
/* è¯é³è¾åºï¼â/âå为æ¿ä»£ææ¬ */
content: url("../img/test.png") / "è¿æ¯æ¿ä»£ææ¬";
/* <string> å¼ */
content: "unparsed text";
/* <counter> å¼ï¼åè·å¯éç <list-style-type> */
content: counter(chapter_counter);
content: counter(chapter_counter, upper-roman);
content: counters(section_counter, ".");
content: counters(section_counter, ".", decimal-leading-zero);
/* attr() å¼ä¼é¾æ¥å° HTML 屿§å¼ */
content: attr(href);
/* <quote> å¼ */
content: open-quote;
content: close-quote;
content: no-open-quote;
content: no-close-quote;
/* <content-list>ï¼content å¼çå表ã
å¯ä»¥åæ¶ä½¿ç¨å¤ä¸ªå¼ */
content: "prefix" url(http://www.example.com/test.png);
content: "prefix" url("/img/test.png") "suffix" / "Alt text";
content: open-quote counter(chapter_counter);
/* å
¨å±å¼ */
content: inherit;
content: initial;
content: revert;
content: revert-layer;
content: unset;
å¼
none-
ä¸ä¼äº§ç伪类å ç´
normal-
:beforeå:after伪类å ç´ ä¸ä¼è¢«è§ä¸ºnone - <string>
-
ææ¬å 容
- <uri>
url() -
URI å¼ä¼æå®ä¸ä¸ªå¤é¨èµæºï¼æ¯å¦å¾çï¼ãå¦æè¯¥èµæºæå¾çä¸è½æ¾ç¤ºï¼å®å°±ä¼è¢«å¿½ç¥ææ¾ç¤ºä¸äºå ä½ï¼æ¯å¦æ å¾çæ å¿ï¼ã
- <counter>
-
计æ°å¨å¯ä»¥æå®ä¸¤ç§ä¸åç彿°ï¼
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-
ä¸ä¼ç产任ä½å 容ï¼ä½æ¯ä¼æ¹åï¼å¢å æéä½ï¼å¼å·å±çº§ã
å½¢å¼å®ä¹
| åå§å¼ | normal |
|---|---|
| éç¨å ç´ | All elements, tree-abiding pseudo-elements, and page margin boxes |
| æ¯å¦æ¯ç»§æ¿å±æ§ | å¦ |
| 计ç®å¼ | On elements, always computes to normal. On ::before and ::after, if normal is specified, computes to none. Otherwise, for URI values, the absolute URI; for attr() values, the resulting string; for other keywords, as specified. |
| å¨ç»ç±»å | 离æ£å¼ |
å½¢å¼è¯æ³
content =
normal |
none |
[ <content-replacement> | <content-list> ] [ / [ <string> | <counter> | <attr()> ]+ ]? |
<element()>
<content-replacement> =
<image>
<content-list> =
[ <string> | <image> | <attr()> | contents | <quote> | <leader()> | <target> | <string()> | <content()> | <counter> ]+
<counter> =
<counter()> |
<counters()>
<attr()> =
attr( <attr-name> <attr-type>? , <declaration-value>? )
<element()> =
element( <id-selector> )
<image> =
<url> |
<image()> |
<image-set()> |
<cross-fade()> |
<element()> |
<gradient>
<quote> =
open-quote |
close-quote |
no-open-quote |
no-close-quote
<leader()> =
leader( <leader-type> )
<target> =
<target-counter()> |
<target-counters()> |
<target-text()>
<string()> =
string( <custom-ident> , [ first | start | last | first-except ]? )
<content()> =
content( [ text | before | after | first-letter | marker ]? )
<counter()> =
counter( <counter-name> , <counter-style>? )
<counters()> =
counters( <counter-name> , <string> , <counter-style>? )
<attr-name> =
[ <ident-token>? '|' ]? <ident-token>
<attr-type> =
type( <syntax> ) |
raw-string |
number |
<attr-unit>
<id-selector> =
<hash-token>
<image()> =
image( <image-tags>? [ <image-src>? , <color>? ]! )
<image-set()> =
image-set( <image-set-option># )
<cross-fade()> =
cross-fade( <cf-image># )
<leader-type> =
dotted |
solid |
space |
<string>
<target-counter()> =
target-counter( [ <string> | <url> ] , <custom-ident> , <counter-style>? )
<target-counters()> =
target-counters( [ <string> | <url> ] , <custom-ident> , <string> , <counter-style>? )
<target-text()> =
target-text( [ <string> | <url> ] , [ content | before | after | first-letter ]? )
<counter-name> =
<custom-ident>
<counter-style> =
<counter-style-name> |
<symbols()>
<syntax> =
'*' |
<syntax-component> [ <syntax-combinator> <syntax-component> ]* |
<syntax-string>
<attr-unit> =
<custom-ident>
<image-tags> =
ltr |
rtl
<image-src> =
<url> |
<string>
<image-set-option> =
[ <image> | <string> ] [ <resolution> || type( <string> ) ]?
<cf-image> =
[ <image> | <color> ] &&
<percentage [0,100]>?
<counter-style-name> =
<custom-ident>
<symbols()> =
symbols( <symbols-type>? [ <string> | <image> ]+ )
<syntax-component> =
<syntax-single-component> <syntax-multiplier>? |
'<' transform-list '>'
<syntax-combinator> =
'|'
<syntax-string> =
<string>
<symbols-type> =
cyclic |
numeric |
alphabetic |
symbolic |
fixed
<syntax-single-component> =
'<' <syntax-type-name> '>' |
<ident>
<syntax-multiplier> =
'#' |
'+'
<syntax-type-name> =
angle |
color |
custom-ident |
image |
integer |
length |
length-percentage |
number |
percentage |
resolution |
string |
time |
url |
transform-function
示ä¾
>æ é¢åå¼å·
HTML
<h1>5</h1>
<p>
We shall start this with a quote from Sir Tim Berners-Lee,
<q cite="http://www.w3.org/People/Berners-Lee/FAQ.html#Internet">
I was lucky enough to invent the Web at the time when the Internet already
existed - and had for a decade and a half.</q
>
We must understand that there is nothing fundamentally wrong with building on
the contributions of others.
</p>
<h1>6</h1>
<p>
Here we shall quote the Mozilla Manifesto,
<q cite="http://www.mozilla.org/en-US/about/manifesto/">
Individuals must have the ability to shape the Internet and their own
experiences on the Internet.</q
>
And so, we can infer that contributing to the open web, can protect our own
individual experiences on it.
</p>
CSS
q {
color: #00008b;
font-style: italic;
}
q::before {
content: open-quote;
}
q::after {
content: close-quote;
}
h1::before {
content: "Chapter ";
}
ç»æ
link åé¢å ä¸ä¸ª icon
HTML
<a href="http://www.mozilla.org/en-US/">Home Page</a>
CSS
a::before {
content: url(http://www.mozilla.org/favicon.ico) " MOZILLA: ";
font:
x-small Arial,
freeSans,
sans-serif;
color: gray;
}
ç»æ
èªå®ä¹å表åé¢å å æå
HTML
<div>
<ul class="brightIdea">
<li>This is my first idea</li>
<li>and another good idea</li>
</ul>
</div>
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;
}
ç»æ
class based example
HTML
<h2>Paperback best sellers</h2>
<ol>
<li>Political thriller</li>
<li class="newEntry">Halloween Stories</li>
<li>My Biography</li>
<li class="newEntry">Vampire Romance</li>
</ol>
CSS
/* use a class rather that an element selector to give more flexibility.
Simple string example, but don't forget add a leading space in the text string
for spacing purposes */
.newEntry::after {
content: " New!";
color: red;
}
ç»æ
rich link styling
HTML
<ul>
<li><a id="moz" href="http://www.mozilla.org/"> Mozilla Home Page</a></li>
<li>
<a id="mdn" href="https://developer.mozilla.org/">
Mozilla Developer Network</a
>
</li>
<li><a id="w3c" href="http://www.w3c.org/"> World Wide Web Consortium</a></li>
</ul>
CSS
a {
text-decoration: none;
border-bottom: 3px dotted navy;
}
a::after {
content: " (" attr(id) ")";
}
#moz::before {
content: url(https://mozorg.cdn.mozilla.net/media/img/favicon.ico);
}
#mdn::before {
content: url(mdn-favicon16.png);
}
li {
margin: 1em;
}
ç»æ
è§è
| è§è |
|---|
| CSS Generated Content Module Level 3 > # propdef-content > |
æµè§å¨å ¼å®¹æ§
åè§
::after::before::markercontainquotes<gradient>image-set()<url>- 坿¿æ¢å ç´
-
CSS çæå 容模å
-
CSS å表å计æ°å¨æ¨¡å
-
æµè§å¨æ éç¢é¢æ¿ï¼Firefox æ éç¢æ£æ¥å¨ãChrome æ éç¢é¢æ¿å Safari æ éç¢æ