web前端:3_初识CSS与文本背景样式

1,css的内部样式表

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>CSS样式表</title>

    <!-- style就是样式,我们可以把CSS样式写在这个标签里 -->
    <style>

    /* 1,标签选择器  选择网页里的所有该标签----全部修改*/
        p {
            color: #096;        /*修改字体颜色*/
            font-size: 70px;   /*修改字体大小*/
        }

        /* 2, id选择器: 先给标签设置id,然后通过 #id名 的方式找到该标签  id是唯一的 一个人使用
        id 只给一个标签加样式*/
        #hot{
            color: red;
            font-size: 20px;
        }

        /* 3,class 选择器(类):先给标签设置class类名/类型  然后通过 .class名 的方式找到该标签
        class 为类型,可以有多个 */
        .money{
            color: blue;
            font-size: 20px;
        }

        /* 4,通配符选择器(*)  *表示选择网页中的所有元素(正式开发不用) 
        <有领导先听领导的,再通配符的>*/
        *{
            color: blueviolet;
            font-size: 50px;
                } 

    </style>
</head>
<body>
    <p>锄禾日当午</p>
    <p>汗滴禾下土</p>
    <p>谁知盘中餐</p>
    <p>粒粒皆辛苦</p>

    <span>xdqwg</span>
    <span class="money">xdqwg</span>
    <span class="money">xdqwg</span>
    <span class="money">xdqwg</span>
    <span class="money">xdqwg</span>
    <span>xdqwg</span>
    <span>xdqwg</span>
    <span>xdqwg</span>
    <span>xdqwg</span>

    <b  id="hot">wdcwe</b>
    <b>wdcwe</b>
    <b>wdcwe</b>
    <b>wdcwe</b>

</body>
</html>

 2,外部样式表  (把CSS代码写入一个专门的.css文件里,需要使用的时候就用link标签导入  类似于py的模块)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>CSS样式写法</title>


    <!-- 外部样式表 -->
    <link rel="stylesheet"  href="demo.css">

    <!-- 内部样式表 -->
    <style>
        .kylin{
            color: brown;
            font-size: 70px;
        }
    </style>
</head>
<body>
    <p class="kylin">朋友们!多喝热水!</p>
    <p class="kylin">朋友们!多喝热水!</p>
    <p class="kylin">朋友们!多喝热水!</p>
    <p class="kylin">朋友们!多喝热水!</p>
    <p class="kylin">朋友们!多喝热水!</p>
    <p class="kylin">朋友们!多喝热水!</p>
    <p class="kylin">朋友们!多喝热水!</p>

    <p  id="heal">学生接触外界才好!</p>
</body>
</html>

css文件

#heal{
    color:#096;
    font-size: 20px;
}

 3,行内样式表   --通过标签属性style直接把样式写在标签里

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>CSS样式写法</title>


    <!-- 1, 外部样式表 
    <link rel="stylesheet" href="文件路径">   -->
    <link rel="stylesheet"  href="demo.css">

    <!-- 2,内部样式表 -->
    <style>
        .kylin{
            color: brown;
            font-size: 70px;
        }
    </style>
</head>
<body>
    <p class="kylin">朋友们!多喝热水!</p>
    <p class="kylin">朋友们!多喝热水!</p>
    <p class="kylin">朋友们!多喝热水!</p>
    <p class="kylin">朋友们!多喝热水!</p>
    <p class="kylin">朋友们!多喝热水!</p>
    <p class="kylin">朋友们!多喝热水!</p>
   

    <p  id="heal">学生接触外界才好!</p>



    <!-- 3, 内部样式表.写在标签里面 -->
    <p style="color: brown; text-align: center; ">我是内部样式表</p>

</body>
</html>

P1:样式表的优先级 (就近原则)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>样式表优先级</title>

    <!-- 样式表的优先级参考就近原则 
     行内样式 > 内部样式/外部样式(谁离标签近就听谁的) -->
    <link ref="stylesheet"  href="demo.css">
    <style>
        b{
            color: blue;
        }
    </style>
</head>
<body>
    <b style="color: #096; font-size: 70px;">我是低温iu</b>
    <b>123</b>
    <b>234</b>
</body>
</html>

 P2 :div盒子

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        /* w300+h300+bgc#096 的盒子 */
        .box{
            width: 300px;
            height: 300px;
            background-color: #096;
            text-align: center;   
        }
        .money{
            color: crimson;
        }
    </style>
</head>
<body>
    <!-- 快速创建一个id为xxx的盒子  #xxx  .box
    快速创建一个 -->

    <div class="box">
        <img src="C:\Users\zxr\Desktop\前端文件\img\皮卡丘.jpg" alt=""  width="100" height="150">
        <h2>我是一只皮卡丘</h2>
        <p>我的技能是十万伏特</p>
        <p>只需<span class="money">998</span>元</p>
    </div>
</body>
</html>

P3:一个标签里面可以有多个类

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>多个类名使用方式</title>
    <style>
        .fs70{
            font-size: 70px;

        }

        .hot{
            color: maroon;
        }
    </style>
</head>
<body>

    <!-- 一个标签里面可以有多个类 -->
    <p class="fs70  hot">鸽子为什么那么大</p>
    <p class="fs70  hot">鸽子为什么那么大</p>
    <p class="fs70  hot">鸽子为什么那么大</p>
    <p class="fs70  hot">鸽子为什么那么大</p>
    <p class="fs70  hot">鸽子为什么那么大</p>
    <p class="fs70  hot">鸽子为什么那么大</p>
    <p class="fs70  hot">鸽子为什么那么大</p>
    <p class="fs70  hot">鸽子为什么那么大</p>
    
    <b class="fs70">cwqhjc</b>
    <b class="fs70">cwqhjc</b>
    <b class="fs70">cwqhjc</b>
  
</body>
</html>

P4:文本样式

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>文本样式</title>

    <style>
        .fan{
            font-size: 70px;  /*字体大小  px像素  em字符大小*/
            font-size: 2em;

            font-family: "Microsoft YaHei";    /*  设置字体(宋体,微软雅黑) */

            font-weight: 900;   /*字体粗细 100~900*/

            font-style: italic;   /*  字体样式   --倾斜*/

            text-indent: 2em;   /*文字缩进  --前缩进2个字*/

            text-align: center;  /*文本对齐  -- 居中*/

            text-decoration: underline;   /*设置文本样式   underline  --设置下划线   none  --去除样式,没有线
                                            overline  --上划线*/
            line-height: 100px;    /* 设置文本的上下位置 */
        }
    </style>
</head>
<body>
    <p  class="fan">剩下的货币</p>
</body>
</html>

P5:背景样式

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>背景样式</title>

    <style>
        body{
            background-color: #096;  /*设置背景颜色*/
            background-image: url(C:\Users\zxr\Pictures\img\1.jpg);  /* 设置背景图片 */
        }

        .box{
            width: 500px;
            height: 500px;
            background-image: url(C:\Users\zxr\Pictures\img\1.jpg);
            background-position: center; /*设置背景位置 */
            background-size: cover;  /*  设置背景大小  cover --等比例缩放*/
            background-repeat: no-repeat;  /*设置背景重复   no-reapt  --背景不重复*/
        }
    </style>

</head>
<body>
        <div class="box">
        
        </div>
</body>
</html>

 作业1:

网页内有3个p标签,写着: 七零老师 / 多喝热水 / #096
用三种css样式写法(行内,内部,外部).给p标签分别添加样式(改字号/变颜色都可,自行发挥)
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>作业3_设置样式</title>
    <style>

        /* 外部设置样式 */
        <link ref="stylesheet" href="demo.css">

        /* 内部设置样式 */
        #water{
            color: crimson;
            font-size: 200px;

        }


        .hot{
            color: deeppink;
            font-weight: 600;
            font-style: italic;  /*倾斜*/
        }

    </style>
</head>
<body>
    <!-- 标签内部设置样式 -->
    <p style="color: darkmagenta;font-size: 2em; ">七零老师</p>
    <p  id="water">多喝热水</p>
    <p  class="hot">#096</p>
</body>
</html>

 作业2:

完成作业图片效果
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>设置文本样式</title>
    <style>
        span{
            font-size: 100px;
            font-family: fantasy;
            text-align: center;
        }

        #A{
            color: blue;
        }

        #B{
            color: darkred;
        }

        #C{
            color: darkorange;
        }

        #D{
            color: blue;
        }

        #E{
            color: dodgerblue;
        }

        #F{
            color: brown;
        }


    </style>
</head>
<body>
    
    <span id="A">G</span>
    <span id="B">o</span>
    <span id="C">o</span>
    <span id="D">g</span>
    <span id="E">l</span>
    <span  id="G">e</span>
    
</body>
</html>

 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值