CSS伪类选择器


原来学习过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:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值