静态资源Css基础语法

1.css的引入方式

<1>内联样式

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>引入方式1</title>
</head>
<body>
    <!--内联样式-->
    <h1 style="color: red; font-size: 20px">Hello World</h1>

    <h1>CSS</h1>
</body>
</html>

<2>内部样式

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>引入方式2</title>
    <!--内部样式-->
    <style>
        div{
            color: red;
            font-size: 20px;
        }
    </style>
</head>
<body>
    <div>div1</div>
    <div>div2</div>
</body>
</html>

<3>外部样式【多个网页需要使用相同的样式时,推荐使用这种方式】

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>外部样式[引入]</title>
<!--    rel是关联的意思,关联的是一个样式表(stylesheet)-->
    <link rel="stylesheet" href="../css/2.css">
</head>
<body>
<div>div1</div>
<div>div2</div>
</body>
</html>

2.注释
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        /*为div标签添加样式*/
        div {
            /*color: red;*/
        }
    </style>
</head>
<body>
<!--div标签-->
<div>div</div>
</body>
</html>

3.基本选择器

【包含全局选择器、元素选择器、类选择器、id选择器等】

<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>基本选择器</title>
    <style>
        /*全局选择器【常用于去外边距】*/
        /** {*/
        /*    background-color: aquamarine;*/
        /*    margin:0;*/
        /*    padding:0;*/
        /*}*/
        /*元素选择器*/
        div {
            color: red;
        }
        /*类选择器*/
        .cls {
            /*margin: 0;*/
            color: blue;
        }
        /*id选择器*/
        #d4 {
            color: green;
        }
        #d5 {
            color: pink;
        }
    </style>
</head>
<body>
<div>div1</div>

<div class="cls">div2</div>
<div class="cls">div3</div>
<h5 class="cls">aaa</h5>

<div id="d4">div4</div>
<div id="d5">div5</div>
</body>
</html>

7.属性选择器

【通过指定的属性名和属性值进行选择】

<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>属性选择器</title>
    <style>
        /*范围越大,则优先级越小,type有具体值则先执行*/
        [type] {
            color: blue;
        }
        [type=password] {
            color: chocolate;
        }
        [type=text] {
            color: pink;
        }
    </style>
</head>
<body>
    用户名:<input type="text"/><br/>
    密码:<input type="password"/><br/>
    邮箱:<input type="email"/><br/>
</body>
</html>

8.伪类选择器

【通过对操作状态进行选择(未访问、悬停、访问中、访问后)】

<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>伪类选择器</title>
    <style>
        a {
            text-decoration: none;
        }
        /*对标签的状态进行选择【伪类选择器】*/
        /*未访问的状态*/
        a:link {
            color: black;
        }
        /*已访问的状态*/
        a:visited {
            color: red;
        }
        /*鼠标悬浮的状态*/
        a:hover {
            color: blue;
        }
        /*已选择的链接状态【正在访问】*/
        a:active {
            color: green;
        }
        /*注意: a:hover必须在css定义中的 a:link 和 a:visited之后,才能生效!
        a:active必须在 css 定义中的 a: hover之后才能生效!
        伪类名称对大小写不敏感。*/
    </style>
</head>
<body>
<a href="http://www.baidu.com" target="_blank">百度一下</a>
</body>
</html>

9.组合选择器

【组合几种选择器进行选择】

<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>组合选择器</title>
    <style>
        /*后代选择器*/
       .top li {
           color: red;
       }
        .center li {
            color: blue;
        }
        /*分组选择器*/
        span,#p1 {
            color: green;
        }
    </style>
</head>
<body>
<div class="top">
    <ol>
        <li>aa</li>
        <li>bb</li>
    </ol>
</div>
<div class="center">
    <ul>
        <li>aa</li>
        <li>bb</li>
    </ul>
</div>

<span>span</span>
<p id="p1">段落1</p>
<p>段落2</p>
</body>
</html>

10.浏览器开发者模式图解

在这里插入图片描述
在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

陪雨岁岁年年

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值