CSS伪类选择器

xiaoxiao2021-02-28  88

原来学习过css伪类选择器,前几天写css发现自己并不熟悉了。这两天把它捡起来复习一下

css伪类选择器是用于向某些元素添加特定的效果。

锚伪类:

包括四种状态,活动状态,未被访问状态,已被访问状态,悬停效果。

example:

a:link {color: #FF0000} a:visited {color: #00FF00} a:hover {color: #FF00FF} a:active {color: #0000FF}

fist-chlid伪类

选择元素的第一个子元素。

example:

第一个<p>颜色变红。

<html> <head> <style type="text/css"> p:first-child { color: red; } </style> </head> <body> <p>some text</p> <p>some text</p> </body> </html> 所有<p>的第一个<i>加粗。

<html> <head> <style type="text/css"> p > i:first-child { font-weight:bold; } </style> </head> <body> <p>some <i>text</i>. some <i>text</i>.</p> <p>some <i>text</i>. some <i>text</i>.</p> </body> </html>第一个子元素<p>下的所有<i> <html> <head> <style type="text/css"> p:first-child i { color:blue; } </style> </head> <body> <p>some <i>text</i>. some <i>text</i>.</p> <p>some <i>text</i>. some <i>text</i>.</p> </body> </html> first-letter伪元素

向文本首字母添加样式。

p:first-letter { color:#ff0000; font-size:xx-large; } :before,:after类

在元素的前面之后添加内容;

example:

h1:before { content:url(logo.gif); }

原来学习过css伪类选择器,前几天写css发现自己并不熟悉了。这两天把它捡起来复习一下

css伪类选择器是用于向某些元素添加特定的效果。

锚伪类:

包括四种状态,活动状态,未被访问状态,已被访问状态,悬停效果。

example:

转载请注明原文地址: https://www.6miu.com/read-76849.html

最新回复(0)