CSS2 selector

CSS2 selector


HTML selector (tag selector):
Use the HTML tag as a selector, the HTML selector

	p{...}
	h1{...}

class selector:
Class selectors can be used repeatedly and precisely in HTML documents by specifying the class attribute for the target tag.

<style>
        .my-class1{color: red;}
</style>


    <HTMLtag class="my-class1">The first element of class name 1</HTMLtag><br/>
    <HTMLtag class="my-class1">The first element of class name 2</HTMLtag><br/>
    <HTMLtag class="my-class2">The first element of class name 1</HTMLtag><br/>


id selector:
The ID selector can be used precisely in an HTML document by specifying a unique ID attribute to the target tag(The ID is unique)

<style>
    #id_name1{color: red;}
    #id_name2{color: blue;}
    </style>


    <HTMLtag id="id_name1">id="id_name1"</HTMLtag><br/>
    <HTMLtag id="id_name2">id="id_name2"</HTMLtag>

Associated selector (including selector)

<style>
    div p{color: red;}
    h1 a{color: blue;}
</style>


<div><p>I'm the P ELEMENT IN DIV</p></div>
<h1><a>I'm the A Element in H1</a></h1>

Combination selector (selector group)

A combination selector can be any selector, such as using a label name, a class name, and an ID name.

<style>
    a,div{color: red;}
</style>


<a>a 元素</a><br/>
<div>div 元素</div>

Pseudo class selector

<style>
	a:link{color: blue; text-decoration: none;} /*Unvisited link*/

	a:visited{color: purple; text-decoration: none;}    /*Accessed link*/

	a:hover{color: pink; text-decoration: underline;}   /*The mouse is on the link*/

	a:active{color: red; text-decoration: underline;}   /*Activate the link*/
</style>
    <a href="https://www.baidu.cn/" target="_blank">Links</a>

When the browser has an access record for the URL address in href, : visited takes effect.

So when you click on try to run the code, the link’s color is defined in: visited, not the style defined in :link.

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值