CSS基础样式、选择器

一、样式

1.内部样式

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- 内部样式 -->
<style>
  h1{color: rgb(0, 0, 0);}
  h2{color: rgb(185, 73, 73);}
  h3{color: rgb(53, 41, 124);}
</style>
      
</head>
<body>
    <h3>nihhjdsvbdj</h3>
    <h2>hgsugvsbvkjdf</h2>
    <h1>gfeuaoetuomvt </h1>
</body>
</html>

2.外部样式

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
     <!-- 外部样式
     href=css文件的路径-->
     <!-- CSS外部引入方式1 -->
<link rel="stylesheet" href="html.css">  
     <!-- CSS外部引入方式2 -->
     <style type="text/css">
        @import url("html.css");
     </style>
</head>
<body>
    <h3>nihhjdsvbdj</h3>
    <h2>hgsugvsbvkjdf</h2>
    <h1>gfeuaoetuomvt </h1>
</body>
/* css外部样式 */
h1{color: rgb(29, 198, 63);}
h2{color: rgb(185, 73, 73);}
h3{color: rgb(53, 41, 124);}

 3.行内样式

<h1 style="color: rgb(210, 25, 99);">gfeuaoetuomvt </h1>
    <div style="color: darkorange;">我是div</div>

 优先级:行内>内部>外部      把!important加到哪种样式属性之后,哪种样式优先级最高(针对同一个标签,同一种属性)

二、选择器

1.元素选择器 

<style>
 div{
    color: rgb(30, 152, 68);
        }
 h1{
    background-color: black;
        }
</style>

<body>
 <div>5555555555555</div>
 <h1>999999999999</h1>
</body>

 2.类选择器

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .color{
            color: rgb(210, 49, 13);
            background-color: rgb(13, 109, 47);
        }
        .ibm{
            background-color: aquamarine;
            color: rgb(29, 4, 57);
        }       
    </style>
</head>
<body>
 <!-- 当一个标签同时拥有几个类选择器,且几个选择器都有相同属性时,style最后定义的属性优先级更高 --> 
    <div class="color ibm">111111111111</div>
    <div class="color">222222222222</div>
    <div class="ibm">33333333333</div>
    <div class="color">44444444444</div>
</body>
</html>

3.id选择器

<style>
#aaa{
     color: #000;
}    
#bbb{
     background-color: blueviolet;
} 
#ccc{
     color: rgb(156, 25, 25);
</style>

<body>
<!-- 一个标签不能用几个id选择器 -->
    <div id="aaa">rrrrrrrrrrr</div>
    <div id="bbb">kkkkkkkkkkk</div>
    <div id="ccc">yyyyyyyyyyy</div>
</body>

4.通配选择器

*{
     /*外边距*/
     margin: 0;
    /*内边距*/
     padding: 0;

 }

5.群组和后代选择器 

<style>
/* 群组选择器 */
div,p,h3{
            background-color: rgb(209, 106, 10);
        }
</style>

<body>
<div>sssssssssssss</div>
<p>wwwwwwwwwww</p>
<h3>ffffffffff</h3>
</body>
/* 后代选择器 (从右向左选择,先找到p,再找到包裹p的div)*/
        div p{
            background-color: chartreuse;
        }
<div>
    <p>kkkkkkkkkk</p>
</div>
<h1>jjjjjjjjjj</h1>

 6.伪类选择器

a:link{
            color: rgb(149, 231, 15);
        }
        a:visited{
            color: rgb(217, 11, 11);
        }
        a:hover{
            color: rgb(40, 19, 181);
        }
        a:active{
            color: rgb(237, 139, 11);
        }

<body>
        <a href="www.baidu.com">百度</a>
</body>

 

  7.选择器的权重

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值