css的选择器

1.基本选择器

在html的基本标签style标签内使用。例如改变div标签内的样式

<html>
   <head>
    <title>html示例</title>
    <style type="text/css">
        div{
            background-color:yellow;
            color:blue;
        }
    </style>
   </head>
   <body>
        <div>测试css的基本选择器</div>
   </body>
</html>

2.css的类选择器

顾名思义就是在标签内添加class属性,然后修改此标签内的属性时,只需要调用类名即可。

<html>
   <head>
    <title>html示例</title>
	<style type="text/css">
		div.haha{
			background-color:red;
			color:black;
		}
		p.xixi{
			background-color:yellow;
			color:gray;
		}
	</style>
   </head>
   <body>
		<div class="haha">css选择器演示二</div>
		<p class="xixi">css选择器演示</p>
   </body>
</html>

 3.id选择器

同样的也是在标签内表明id属性,只不过使用标签名调用时调用的方法与类选择器不同

调用方式为:标签名#id名

<html>
   <head>
    <title>html示例</title>
	<style type="text/css">
		div#hehe{
			background-color:yellow;
			color:gray;
		}
	</style>
   </head>
   <body>
    <div id="hehe">css的id选择器</div>

   </body>
</html>

 

4.选择器之间的优先级关系

style>id选择器>类选择器>标签选择器 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值