css-web前端必须掌握的基础部分1

这篇博客详细介绍了CSS的三种引入方式:外部样式表、内部样式表和内联样式表,并通过实例展示了如何使用@import导入其他CSS文件。同时,文章涵盖了背景色、背景图、文本样式和常见选择器的用法,包括颜色表示、背景尺寸调整、文本对齐、选择器优先级等知识点,是理解CSS样式的实用教程。
摘要由CSDN通过智能技术生成

  <title>css的引入方式</title>

    <!-- 外部样式表 -->

    <!-- <link rel="stylesheet" href="css/first.css"> -->

    <style>

        /* 引入其他的css样式 */

        @import url("css/second.css");

        /* 内部样式表 */

        div{

            width: 100px;

            height: 100px;

            background-color: red;

        }

    </style>

</head>

<body>

    <div></div>

    <p>11111</p>

    <!-- 内联样式表 -->

    <div style="width: 200px;background-color:cyan"></div>

</body>

    <title>背景色</title>

    <!-- 网页三原色:红 绿 蓝 -->

    <style>

        div{

            width: 200px;

            height: 100px;

            /* background-color: gold; */

            /* background-color: rgba(255,0,0,1); */

            background-color: #ff0000;

        }

    </style>

</head>

<body>

    <div></div>

</body>

</html>

<!-- 三种方式来表示颜色:单词 rgba(红 绿 蓝 透明度)  rgb 十六进制 -->

</html>

<!-- 内部样式表和外部样式表取决于哪个后引入  内联样式表的优先级是最高的 -->

    <title>背景图</title>

    <style>

        img{

           width: 180px;

           height: 100px;

        }

        div{

            width: 400px;

            height: 400px;

            background-color: red;

            background-image: url(img/dm.png);

            background-size: cover;

            background-position: center center;

             background-repeat: no-repeat;

        }

    </style>

</head>

<body>

    <img src="img/dm.png" alt="">

    <div>

        <p>这是一只瑞希</p>

    </div>

</body>

</html>

<!-- background-size:w(宽度) h(高度);

     如果只给其中一个,另一边会等比例变化

    两个特殊的值:contain:图片的场边占满父级

                 cover:  图片的短边占满父级-->

    <title>文本</title>

    <style>

        *{

            margin: 0;

            padding:0;

        }

        html{

            font-size:16px;

        }

        p{

            color: skyblue;

            /* height: 50px; */

            background-color: pink;

            font-size: 30px;

            /* 14px是一般浏览器允许的最小像素,16px是浏览器的默认像素 */

            /* font-size: 4em; */

            font-family: 'Courier New', Courier, monospace ;

            /* 文本对齐方式 */

            text-align: left;

            line-height: 50px;

            /* 首行缩进 */

            text-indent: 2em;

            /* text-indent: 100px; */

            /* 字体间距 */

            letter-spacing: 5px;

            /* 单词间距 */

            word-spacing: 10px;

            /* 文本大小写 */

            text-transform: uppercase;

        }

            a{

                /* 文本装饰线 */

                font-size: 40px;

                text-decoration:none;

            }

        }

    </style>

</head>

<body>

    <p>巴卫这只狐狸很帅气,巴卫这只狐狸很帅气,巴卫这只狐狸很帅气,巴卫这只狐狸很帅气</p>

    <p>welcome to csdn</p>

    <a href="http://ac.csdn.net">csdn</a>

</body>

</html>

<!-- em是相对单位   1em等于父级标签的字体大小 -->

<!-- 当line-height的值等于height的值,文本垂直居中 -->

    <title>常用的选择器</title>

    <style>

        *{

            margin: 0px;

            padding: 0px;

            list-style: none;

        }

        h1,p{

            /* 群组选择器 */

            color: red;

        }

        .c{

            /* class选择器 */

            color: green;

        }

        #big{

            font-size: 30px;

            color: blue;

        }

        div p{

            /* 后代选择器 */

            color: cyan;

        }

        div>p{

            /* 子代:直接子集 */

            color: pink;

        }

        /* 属性选择器 */

        [class="ok"]{

            /* 最好具体带上之后的名称,哪个标签有class */

            color: gold;

        }

    </style>

</head>

<body>

    <p>123</p>

    <h1>welcome to csdn</h1>

    <p class="c">csdn</p>

    <p class="c" id="big">天天向上</p>

    <ul>

        <li class="ok">一二三四</li>

        <li>以而散思</li>

        <li>怡尔叁斯</li>

    </ul>

    <div>

        <p>人生若只如初见</p>

        <span><p>何事秋风悲画扇</p></span>

    </div>

</body>

</html>

<!-- 一个id名,在同一个html文件中只能出现一次 -->

<!-- 优先级:id(权重100)>class(10)>tag(1)  -->

<!-- 内联样式权重1000 -->

<!-- 后代选择器权重相加(权重越高数字越小) -->

@import url("second.css");

/* 在css里面引入其他的css文件 */

first.css

div{

    width: 200px;

    height: 200px;

    background-color: pink;

}

second.css

目录

  

css的引入方式

    

背景色

    

背景图

    

文本

    

常用的选择器


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值