html之css基础总结

CSS的引用

  <!-- 内部样式表 -->
    <style>
        /* css中注释 */
        /* 选择器{
            属性:值;
            属性:值;
            ......
        } */
    </style>
    <!-- 外部样式 -->
    <link rel="stylesheet" href="./test.css">
</head>
<body>
    <!-- 行内样式表 -->
    <h1 style="">标题</h1>

常用外观样式

<style>
        div{
            font-size: 30px;
            text-indent: 2em;
            color: rosybrown;
			/* 五种设置方式 */
            /* 1 英文单词  */
            color:orange;
            /* 2 6位16进制,前两位红色,中间两位绿色,最后两位蓝色 */
            color: #F25643;
            /* 3 3位16进制 */
            color: #f00;
            /* 4 rgb ,可以写百分比和 0-255的整数*/
            color: rgb(50%, 0%, 0%);
            /* 5 rgba , 第四个是透明度 0 - 1 之间的小数,0是完全透明*/
            color: rgba(255, 0, 0, 0.5);
        }
        h2{
            text-align: center;
            text-decoration: underline;
            text-decoration: line-through;
            text-decoration: overline;
        }
        p{
            text-align: center;
            border: 1px solid blue;
            line-height: 100px;
            cursor: pointer;
            background-color: silver;
            display: inline-block;
            text-decoration: underline;
        }
        a{
         /* 清除文本修饰,比如a标签默认的下划线 */
            text-decoration: none;
        }
    </style>
</head>
<body>
    <h2>sdfasdfcxcv安抚</h2>
    <div>sadfsa啊手动阀手动阀撒旦发sadfsa啊手动阀手动阀撒旦发sadfsa啊手动阀手动阀撒旦发sad
        fsa啊手动阀手动阀撒旦发sadfsa啊手动阀手动阀撒旦发sadfsa啊手动阀手动阀撒旦发</div>

<div style="color:deepskyblue; text-align: center; text-indent: 0mm;">
    <p title="zhushi"><a href="所发生的">风飒飒大费</a></p>
    <p>osdafasdf啊撒打发</p>
</div>

在这里插入图片描述

字体设置

    <style>
        p{
            font-size:40px ;
            font-family:"KaiTi","微软雅黑","黑体" ;
            font-style: oblique;
            font-weight: 600;
        }
        span{
            /* 风格 , 粗细 , 大小, 字体  字体和大小必须写,否则不生效 */
            font: 40px "KaiTi";
        }
    </style>

通配符

对页面中所有元素进行样式设置

        *{
            color: red;
            。。。。。。
        }

伪元素

<style>
    .t{
        color: lightblue;
        position: relative;
        top: 200px;
    }
    h1{
        border: 1px solid black;
        color: lightblue;
        text-align: center;
    }
    h1:hover{
        color: black;
        position: relative;
        top:4px;
        cursor: pointer;

    }

    a:link{
        color: indigo;
        text-decoration: none;
    }
    a:hover{
        color: cornflowerblue;
        position: relative;
        top: 1px;
        left: 1px;
    }
    a:visited{
        color: crimson;
    }
    a:active{
        color: green;
    }


 
</style>
<body>
    <h1>href</h1>
    <table class="t" border="1" align="center" cellspacing="0" cellpadding="25" >
        <tr>
            <td>
                <a href="#7">登录</a>
                <a href="#1">注册</a>
                <a href="#3">注销</a>
                <a href="#4">忘记密码</a>
            </td>
        </tr>
    </table>
</body>

在这里插入图片描述

有父代,子代时对子代设置

    <style>
      /* 对子类设置 */
        ul>li>a{
            color: red;
        }
    </style>
</head>
<body>
    <ul>
        <a href="">子标签</a>
        <li><a href="">孙标签</a></li>
    </ul>
</body>

在这里插入图片描述

类选择器

<style>
        p{
            text-indent: 2em;
            color: silver;
            font-size: 30px;
        }
        .a{
            color: blue;
            text-align: center;
        }
        p.a{
            text-indent: 0mm;
            color: rgb(0, 0, 0);
        }
        .c{
            color: gold;
        }
        .s{
            font-size: 80px;
        }
    </style>
</head>
<body>
    <h2 class="a">标题</h2>
    <p>啊发射点发离开剧场效率及阿尔u离开剧场效率及阿尔u离开剧场
        效率及阿尔u离开剧场效率及阿尔u离开剧场效率及阿尔u离开剧场效率及阿尔u日欧方式</p>
    <p class="a">only</p>
    <!-- 可以设置多个class值,多个用空格隔开 -->
    <p class="s c">saf</p>
</body>

在这里插入图片描述

id选择器

<Style>
    .a{
        color: rgb(0, 0, 0);
        font-size: 20px;
    }
    #d{
        font-size: 80px;
        color: blur;
        text-align: center;
    }

</Style>
</head>
<body>
    <p class="a" id="d">fasfsf</p>
    <p id="d" class="a">fasdfa</p>
</body>

在这里插入图片描述

块状元素,行内元素

1块状元素有哪些 其特征是什么
div , p , h1~h6 , ol , ul , dl , form , table , address,li,hr,nav,header
每个块级元素都独占,元素的宽度、高度、行高及顶部和底部边距可以设置
元素宽度在不设置的情况下,和它父元素的宽度一致。
2 行内元素有哪些 其特征是什么
span , a , em , b , i , strongimg , input , td,select,br,sup,del
元素的宽度、高度及顶部和顶部边距都不能设置,元素的宽度就是它所包含的文字或图片的宽度,不可修改。

        /* 转换为行内块 */
        /* display: inline-block; */
        /* 转换为行内元素 */
        /* display: inline; */
        /* 转换为块元素 */
        /* display: block; */
    /* }
    span:hover{
        /* 设置为none可以隐藏标签,并且也没中就没有这个标签了,不会预留位置 */
        /* display: none; */
    /* } */ 

背景位置设置

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>

            /* 转换为行内块 */
            /* display: inline-block; */
            /* 转换为行内元素 */
            /* display: inline; */
            /* 转换为块元素 */
            /* display: block; */
        /* }
        span:hover{
            /* 设置为none可以隐藏标签,并且也没中就没有这个标签了,不会预留位置 */
            /* display: none; */
        /* } */ 

    .d{
        border:1px solid red;
        height: 300px;
        width: 300px;
        background-image: url(./tianshi.gif);
        background-repeat: no-repeat;
        /*背景综合写法
         background: pink url(./img/1.jpg) no-repeat scroll center; */
        /* 设置平铺 : no-repeat(不平铺) , repeat-x (x轴平铺) , repeat-y(y轴平铺) , repeat(x,y都平铺)  */
        background-position: bottom right;
        display: inline-block;
    }
    .e{
        border:1px solid red;
        height: 300px;
        width: 300px;
        background-image: url(./tianshi.gif);
        background-repeat: no-repeat;
        background-position: 100% 100%;
        display: inline-block;
    }
    .f{
        border:1px solid red;
        height: 300px;
        width: 300px;
        background-image: url(./tianshi.gif);
        background-repeat: no-repeat;
        background-position: 200px 200px;
        display: inline-block;
    }
</style>
<body>
    <div class="d"></div>
    <div class="e"></div>
    <div class="f"></div>
</body>
</html>

CSS复合选择器总结

并集选择器

    <style>
        /* 公共的属性设置 */
        p,.a{
            color: blue;
            text-align: center;
            font-size: 50px;
        }
        .a{
           font-size: 70px;  
        }
    </style>
</head>
<body>
    <p>asdf</p>
    <h3 class="a">sdfsadf</h3>
</body>

交集选择器 交集选择器 是 并且的意思。 即…又…的意思
交集选择器由两个选择器构成,其中第一个为标签选择器,第二个为class选择器,两个选择器之间不能有空格,如h3.special。
在这里插入图片描述
后代选择器
后代选择器又称为包含选择器,用来选择元素或元素组的后代,其写法就是把外层标签写在前面,内层标签写在后面,中间用空格分隔。当标签发生嵌套时,内层标签就成为外层标签的后代。
在这里插入图片描述
子元素选择器
子元素选择器只能选择作为某元素子元素的元素。其写法就是把父级标签写在前面,子级标签写在后面,中间跟一个 > 进行连接,注意,符号左右两侧各保留一个空格。
在这里插入图片描述

    <style>
      /* 对子类设置 */
        ul>li>a{
            color: red;
        }
    </style>
</head>
<body>
    <ul>
        <a href="">子标签</a>
        <li><a href="">孙标签</a></li>
    </ul>
</body>

属性选择器
选取标签带有某些特殊属性的选择器 我们称为属性选择器

    <style>
        div{
            text-align: center;
          
        }
        input[type='button']{
            border-radius: 3px;
            color: blue;
        }
        input[id]{
            color: red;
        }
        a[href^='http']{
            color: red;
        }
        a[href$='com1']{
            color: gold;
        }
    </style>
</head>
<body>
    <div>
        <input type="button" value="shuru2">
        <input type="button" id="" value="shuru">
        <input type="text" name="">
        <a href="http://www.taobao.com">淘宝</a>
        <a href="www.baidu.com1">百度</a>
    </div>
</body>

在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值