CSS-因为选择装饰而美

2018-05-18  本文已影响0人  Python野路子

CSS

css样式的多种形式

    <link rel="stylesheet" href="index.css">  <!--外链css样式,在style之前引入)-->
    div{
            width: 200px;
            height: 200px;
            background: red;
        }
<div style="width: 200px;height: 200px;background: red;"></div>

样式优先级

即是指CSS样式在浏览器中被解析的先后顺序。
外链css样式 < (内嵌css)样式 < 行间样式

css选择器

        *{
            margin: 0;
            padding: 0;
        }
        div{
            width: 100px;
            height: 100px;
            background: darkred;
        }
        #box{
            width: 150px;
            height: 150px;
            background: bisque;
        }  
/*在一个页面中,同名id只能出现一次*/
        .box{
            width: 120px;
            height: 120px;
            background: cornflowerblue;
        }
div,p{
            width: 120px;
            height: 120px;
            background: bisque;
        } 
        div~p{                      /*选择div后面所有兄弟元素p,之前的不管*/
            width: 100px;
            height: 100px;
            background: red;
        }
        div + p{
            width: 100px;
            background: blueviolet;
            height: 100px;
        }
        div>div{            /*选择div下面的子元素div3,其他不管了*/
            width: 50px;
            height: 50px;
            background: blue;
        }
        div ul li{            /*选择div下ul下的li*/
            width: 70px;
            height: 70px;
            background: greenyellow;
        }
        a:link{  /*:link 未被点击的链接*/
            color: red;
        }
        a:visited{ /*已被点击的链接*/
            color: darkgoldenrod;
        }
        a:hover{ /*鼠标悬停其上的元素  这个一定要掌握*/
            color: yellowgreen;
        }
        a:active{ /*鼠标已经再其上按下但是还没有释放的元素*/
            color: aqua;
        }   
/*要全部有效果,需按照w3c的规定,上面顺序*/
        a:link,a:visited,a:hover,a:active{
            color: blue;
            cursor: pointer;           
            text-decoration: none; /*去掉下划线*/
        }

hover拓展:
.box:hover{}    改变div元素本身,
.box:hover p{} 改变div元素下面的p子元素*/
div:hover{ /*改变的是div本身*/
            background: red;
            cursor: pointer;  *!!*手指
            cursor: help;  *!!*帮助
            cursor: wait;  *!!*等待
            cursor: default;  !*默认通常是一个箭头
        }
        div:hover p{ /*鼠标悬停在div上,改变的是p元素*/
            width: 50px;
            height: 50px;
            background: blue;
        }
        a{
            cursor: pointer;
            text-decoration: none;
        }

选择器优先级

.wrap{background:red}
.wrap{background:green}
#指定每个 p 元素匹配的父元素中第 2 个子元素的背景色:
p:nth-child(2)
{
    background:#ff0000;
}
p:nth-of-type(2)
{
  background:#ff0000;
}

table表格

表格的常用标签

学以致用

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>table表格</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        table{
            width: 320px;
            height: 220px;
            border-collapse: collapse; /*合并列*/

        }
         /*
            collapse 边框合并,如果相邻的话,共用一个框
            separate 默认值,边框分开,不合并
            */
        tr{
            /*文字水平居中*/
            text-align: center;
        }

        thead:hover tr{
            background: red;
            color:white;
        }
        th:hover{
            background: blue;
        }

        tr:hover{
            background: yellow;
            color:red;
        }
    </style>
</head>
<body>
    <table border="1">
        <caption><b>学生信息</b></caption>
        <thead>
            <tr class="tc">
                <th>学号</th>
                <th>姓名</th>
                <th>课程</th>
                <th>性别</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>20170001</td>
                <td>小明</td>
                <td>web前端</td>
                <td>男</td>
            </tr>
            <tr>
                <td>20170002</td>
                <td>小红</td>
                <td>大数据</td>
                <td>女</td>
            </tr>
            <tr>
                <td>20170003</td>
                <td>小王</td>
                <td>爬虫</td>
                <td>男</td>
            </tr>
            <tr>
                <td>20170004</td>
                <td>小林</td>
                <td>人工智能</td>
                <td>女</td>
            </tr>
            <tr>
                <td>20170005</td>
                <td>小陈</td>
                <td>web网站</td>
                <td>男</td>
            </tr>
        </tbody>
    </table>
</body>
</html>
image.png
image.png
image.png
上一篇 下一篇

猜你喜欢

热点阅读