css有下列伪类 :active :after, :before :first :first-child :first-letter :first-line :focus :hover :lang :left :link :right :visited = ~= |=css
:link 连接未被访问时的样式 html
:visited 连接被访问后的样式ide
:hover 当鼠标放在一个元素上面时应用字体
:active 当一个元素被用户激活时应用css,例如在用户按下鼠标后,释放鼠标前会激活元素。spa
:lang(C) 若是html元素指定lang属性(注意是html元素) ,那么能够用lang伪类指定相关css属性。C表示相关语言的代码标识。具体可参考 http://www.w3school.com.cn/tags/html_ref_language_codes.aspssr
:first-line 给一个块级容器元素第一行文本应用css, 注意该伪类只能应用于块级容器元素.例如p指针
:first-letter 给一个块级容器元素的第一行的文本的第一个字母应用css,而且该行内第一个字母前不能出现出现如图片之类的元素。code
经过给first-letter应用float:left能够使得第一个字母能够占据左边多行,具体行数取决于字体大小。效果以下。orm
注意标点符号出如今第一行的第一个字母时不算作第一个字母,但应用first-letter样式时会应用该标点符号。效果以下htm
:before 用于给该元素前面插入内容,属性为content
:after 用于给该元素后面插入内容,属性为content
content属性:
值:normal | none | [ <string> | <uri> | <counter> | attr(<identifier>) | open-quote | close-quote | no-open-quote | no-close-quote ]+ |inherit
.class | .intro | 选择 class="intro" 的全部元素。 | 1 |
#id | #firstname | 选择 id="firstname" 的全部元素。 | 1 |
* | * | 选择全部元素。 | 2 |
element | p | 选择全部 <p> 元素。 | 1 |
element,element | div,p | 选择全部 <div> 元素和全部 <p> 元素。 | 1 |
element element | div p | 选择 <div> 元素内部的全部 <p> 元素。 | 1 |
element>element | div>p | 选择父元素为 <div> 元素的全部 <p> 元素。 | 2 |
element+element | div+p | 选择紧接在 <div> 元素以后的全部 <p> 元素。 | 2 |
[attribute] | [target] | 选择带有 target 属性全部元素。 | 2 |
[attribute=value] | [target=_blank] | 选择 target="_blank" 的全部元素。 | 2 |
[attribute~=value] | [title~=flower] | 选择 title 属性包含单词 "flower" 的全部元素。 | 2 |
[attribute|=value] | [lang|=en] | 选择 lang 属性值以 "en" 开头的全部元素。 | 2 |
:link | a:link | 选择全部未被访问的连接。 | 1 |
:visited | a:visited | 选择全部已被访问的连接。 | 1 |
:active | a:active | 选择活动连接。 | 1 |
:hover | a:hover | 选择鼠标指针位于其上的连接。 | 1 |
:focus | input:focus | 选择得到焦点的 input 元素。 | 2 |
:first-letter | p:first-letter | 选择每一个 <p> 元素的首字母。 | 1 |
:first-line | p:first-line | 选择每一个 <p> 元素的首行。 | 1 |
:first-child | p:first-child | 选择属于父元素的第一个子元素的每一个 <p> 元素。 | 2 |
:before | p:before | 在每一个 <p> 元素的内容以前插入内容。 | 2 |
:after | p:after | 在每一个 <p> 元素的内容以后插入内容。 | 2 |
:lang(language) | p:lang(it) | 选择带有以 "it" 开头的 lang 属性值的每一个 <p> 元素。 | 2 |
element1~element2 | p~ul | 选择前面有 <p> 元素的每一个 <ul> 元素。 | 3 |
[attribute^=value] | a[src^="https"] | 选择其 src 属性值以 "https" 开头的每一个 <a> 元素。 | 3 |
[attribute$=value] | a[src$=".pdf"] | 选择其 src 属性以 ".pdf" 结尾的全部 <a> 元素。 | 3 |
[attribute*=value] | a[src*="abc"] | 选择其 src 属性中包含 "abc" 子串的每一个 <a> 元素。 | 3 |
:first-of-type | p:first-of-type | 选择属于其父元素的首个 <p> 元素的每一个 <p> 元素。 | 3 |
:last-of-type | p:last-of-type | 选择属于其父元素的最后 <p> 元素的每一个 <p> 元素。 | 3 |
:only-of-type | p:only-of-type | 选择属于其父元素惟一的 <p> 元素的每一个 <p> 元素。 | 3 |
:only-child | p:only-child | 选择属于其父元素的惟一子元素的每一个 <p> 元素。 | 3 |
:nth-child(n) | p:nth-child(2) | 选择属于其父元素的第二个子元素的每一个 <p> 元素。 | 3 |
:nth-last-child(n) | p:nth-last-child(2) | 同上,从最后一个子元素开始计数。 | 3 |
:nth-of-type(n) | p:nth-of-type(2) | 选择属于其父元素第二个 <p> 元素的每一个 <p> 元素。 | 3 |
:nth-last-of-type(n) | p:nth-last-of-type(2) | 同上,可是从最后一个子元素开始计数。 | 3 |
:last-child | p:last-child | 选择属于其父元素最后一个子元素每一个 <p> 元素。 | 3 |
:root | :root | 选择文档的根元素。 | 3 |
:empty | p:empty | 选择没有子元素的每一个 <p> 元素(包括文本节点)。 | 3 |
:target | #news:target | 选择当前活动的 #news 元素。 | 3 |
:enabled | input:enabled | 选择每一个启用的 <input> 元素。 | 3 |
:disabled | input:disabled | 选择每一个禁用的 <input> 元素 | 3 |
:checked | input:checked | 选择每一个被选中的 <input> 元素。 | 3 |
:not(selector) | :not(p) | 选择非 <p> 元素的每一个元素。 | 3 |
::selection | ::selection | 选择被用户选取的元素部分。 | 3 |
a:link { color: red } /* unvisited links */ a:visited { color: blue } /* visited links */ a:hover { color: yellow } /* user hovers */ a:active { color: lime } /* active links */ html:lang(fr-ca) { quotes: '« ' ' »' } p:first-line { text-transform: uppercase } p:first-letter { font-size: 3em; font-weight: normal }
counter:
BODY { counter-reset: chapter; /* Create a chapter counter scope 设置chapter为0*/ } H1:before { content: "Chapter " counter(chapter) ". "; counter-increment: chapter; /* Add 1 to chapter */ } H1 { counter-reset: section; /* Set section to 0 */ } H2:before { content: counter(chapter) "." counter(section) " "; counter-increment: section; }