CSS

层次选择器
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>


    <style>
        /*1.后代选择器*/
        /*body p{*/
           /*background: red;*/
        /*}*/

    /*    2.子选择器*/
        /*body >p{*/
            /*background: red;*/
        /*}*/
        /*3.相邻兄弟选择器 必须靠近 只取相邻的下面的*/
        /*.action +p{*/
            /*background: red;*/
        /*}*/
        /*4.通用兄弟选择器 会选择下面的所有指定的标签的兄弟选择器(对下不对上)*/

        /*.action~p{*/
            /*background: red;*/
        /*}*/
        /*.action~div{*/
            /*background: red;*/
        /*}*/
        #div~p{
            background: red;
        }


    </style>
</head>

<!--
1.后代选择器
2.子选择器
3.相邻兄弟选择器
4.通用选择器
-->


<body>


<p>p1</p>
<p>p2</p>
<p>p3</p>
<p class="action">p4</p>
<p>p5</p>

<div class="div">
    <p>p6</p>
    <p>p7</p>
    <p>p8</p>
</div>

<p>p9</p>

<div>
    <p>p6</p>
    <p>p7</p>
    <p>p8</p>
</div>

<div>

    <div  >
        <p id="div">p6</p>
        <p>p7</p>
        <p>p8</p>
    </div>

</div>


</body>
</html>
结构伪类选择器
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        /*ul第一个*/
        ul li:first-child{
            background: red;
        }
        /*ul第二个*/
        ul li:last-child{
            background: green;
        }
        /*
        选中当前p元素的父级元素,选中父级元素的第一个(按照顺序)
        */
        p:nth-child(3){
        background: green;
         }
        /**/
        /*选中当前p元素的父级元素,选中下的第3个(按照类型)*/
        p:nth-of-type(3){
            background: yellow;
        }
    </style>


</head>
<body>
<li>1</li>
<p>p1</p>
<p>p2</p>
<p>p3</p>
<ul>
    <li>1</li>
    <li>2</li>
    <li>3</li>
    <li>4</li>
</ul>


<ul>
    <li>1</li>
    <li>2</li>
    <li>3</li>
    <li>4</li>
</ul>

</body>
</html>
属性选择器
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .demo >a{
            float: left;
            display: block;
            height: 50px;
            width: 50px;
            border-radius: 10px;
            background: blue;
            text-align: center;/*居中*/
            color: gainsboro;
            text-decoration: none;/*去下划线*/
            font: bold 25px/50px Arial;
        }
        /*属性名,属性名=属性值(正则)*/

        /*存在id属性的元素*/
    /*  a[id]{
          background: yellow;
      }*/
        /*存在id指定属性的元素*/
        /*a[id=first]{*/
            /*background: #20ff72;*/
        /*}*/

        /*选贼class有links的*/
        /*
        =决定等于
        *=包含
        ^=以什么开头
        $=以什么结尾
        */
        /*a[class *="links"]{*/
        /*background: #20ff72;*/
        /*}*/

        /*选中那个href以image开头的元素*/
        /*a[href^=image]{*/
            /*background: #20ff72;*/
        /*}*/
        /**/
        /*选中href以jpg结尾的元素*/
        a[href$=jpg]{
        background: yellow;
        }
        
    </style>
</head>
<p class="demo">
    <a href="http://www.baidu.com" class="links item first" id="first">1</a>
    <a href="" class="links item active"  target="_blank" title="2">2</a>
    <a href="images/123.html" class="links item">3</a>
    <a href="image/123.png" class="links item">4</a>
    <a href="image/123.jpg" class="links item">5</a>
    <a href="abc" class="links item">6</a>
    <a href="abc.png">7</a>
    <a href="abc.jpg">8</a>
    <a href="abc.html">9</a>
    <a href="abc.txt"  class="links item">10</a>
</p>
<body>
</body>
</html>
字体样式
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>

<style>
    /*font-family:字体
    font-size :字体大小
    font-weight:字体的粗细
    color:字体的颜色
    */

    body{
        font-family: Arial, 楷体;
        color: red;
    }
    h1{
        font-size: 50px;
    }
    .p1{
        font-weight: bold;
    }

</style>
<body>
<h1>故事介绍</h1>
<p class="p1">拥有财富、名声、权力,这世界上的一切的男人 “海贼王”哥尔·D·罗杰,在被行刑受死之前说了一句话,让全世界的人都涌向了大海。“想要我的宝藏吗?如果想要的话,那就到海上去找吧,我全部都放在那里。”,世界开始迎接“大海贼时代”的来临 。</p>
<p>时值“大海贼时代”,为了寻找传说中海贼王罗杰所留下的大秘宝“ONE PIECE”,无数海贼扬起旗帜,互相争斗。有一个梦想成为海贼王的少年叫路飞,他因误食“恶魔果实”而成为了橡皮人,在获得超人能力的同时付出了一辈子无法游泳的代价。十年后,路飞为实现与因救他而断臂的香克斯的约定而出海,他在旅途中不断寻找志同道合的伙伴,开始了以成为海贼王为目标的冒险旅程</p>



<p class="english">THEVALUEOFTIME  baiTorealizethevalueofoneyear:Askastudentwhohasfailedafinalexam.Torealizethevalueofonemonth:Askamotherwhohasgivenbirthtoaprematurebaby.Torealizethevalueofoneweek:Askaneditorofaweeklynewspaper.Torealizethevalueofonehour:Asktheloverswhoarewaitingtomeet.Torealizethevalueofoneminute:Askapersonwhohasmissedthetrain,busorplane.Torealizethevalueofonesecond:Askapersonwhohassurvivedanaccident.Torealizethevalueofonemillisecond:AskthepersonwhohaswonasilvermedalintheOlympics.Timewaitsfornoone.Treasureeverymomentyouhave.</p>

</body>
</html>
文本样式
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
    /*text-indent:首行缩进
    em2个字
    line-height   行高和块的高度一样的话,就可以上下居中
    */
        .p1{
            font-size: 20px;
            text-indent: 2em;
            line-height: 30px;
            background: red;
        }

        p:nth-of-type(1){
            font-size: 20px;
            background: blue;
            line-height: 10px;
        }
        /*下划线*/
        .l1{
            text-decoration: underline;
        }
        /*中划线*/
        .l2{
            text-decoration:line-through;
        }
        /*上划线*/
        .l3{
            text-decoration:overline;
        }
    /*图片和文字的水平对齐*/
        #span,#image{
        vertical-align: middle;
        }
   /*超链接去下划线*/
        a{
            text-decoration: none;
        }
            /*10px 水平   -10px 垂直 2px 阴影半径*/

    </style>
    

</head>
<body>
<a href="http://www.baidu.com">百度一下</a>


<li class="l1">123123123</li>
<li class="l2">123123123</li>
<li class="l3">312313313</li>
<h1>故事介绍</h1>
<p>123</p>
<p class="p1">拥有财富、名声、权力,这世界上的一切的男人 “海贼王”哥尔·D·罗杰,在被行刑受死之前说了一句话,让全世界的人都涌向了大海。“想要我的宝藏吗?如果想要的话,那就到海上去找吧,我全部都放在那里。”,世界开始迎接“大海贼时代”的来临 。</p>
<p>时值“大海贼时代”,为了寻找传说中海贼王罗杰所留下的大秘宝“ONE PIECE”,无数海贼扬起旗帜,互相争斗。有一个梦想成为海贼王的少年叫路飞,他因误食“恶魔果实”而成为了橡皮人,在获得超人能力的同时付出了一辈子无法游泳的代价。十年后,路飞为实现与因救他而断臂的香克斯的约定而出海,他在旅途中不断寻找志同道合的伙伴,开始了以成为海贼王为目标的冒险旅程</p>


<p ><img src="image/a.jpg" alt="加载失败" title="爱你" id="image"> <span id="span">3123123123</span></p>
</body>
</html>
超链接伪类
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<style>
    /*默认的元素*/
    a{
        text-decoration: none;
        color: black;
    }
    /*鼠标悬浮的颜色*/
    a:hover{
        color:orange;
        font-size: 40px;
    }
    /*鼠标按住的状态*/
    a:active{
        color: green;
    }

/*阴影*/
    /*10px 水平   -10px 垂直 2px 阴影半径*/
    #money{
        text-shadow: red 10px -10px  2px;
    }

</style>
<body>

<a href="#">
    <img src="image/1.jpg" alt="加载失败">
</a>

<p>
    <a href="#">坚持就是胜利</a>
</p>
<p>
    <a  href="#">作者:戴宝华</a>
</p>
<p>
    <a id="money"  href="#">¥99</a>
</p>
</body>
</html>
列表
a{
    font-size: 18px;
    font-family: 楷体,Arial;
    text-decoration: none;
    color: gray;
}
a:hover{
    /*text-decoration:red;*/
    color:red;
    text-decoration: underline;

}
/*
list-style:none 去点
        circle 空心园
        decimal 数字*/
ul li{
    height: 30px;

    list-style: none    ;
}
#nav{
    color: gray;
    background: aliceblue;
    width:275px;
}
背景图片
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

    <style>
        /* 边框:border: 1px  solid red; 1px :大小 solid:实现 red:边框颜色*/
        div{
            width: 1000px;
            height: 600px;
            border: 1px  solid grey;
            background-image: url("image/1.jpg");/*默认是全部平铺的*/
        }
        .div1{
            background-repeat: repeat-x;/*横向平铺*/
        }
        .div2{
            background-repeat: repeat-y;/*纵向平铺*/
        }
        .div3{
            background-repeat: no-repeat;/*不平铺*/
            /*图片定位*/
            background-position: 163px -15px;
        }

        body{
            background-color: #FAACA8;
            background-image: linear-gradient(19deg, #FAACA8 0%, #DDD6F3 100%);

        }

    </style>
</head>
<body>

<div class="div1"></div>
<div class="div2"></div>
<div class="div3"></div>

</body>
</html>
盒子模型

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-3l2yatfk-1592817183475)(C:\Users\20190831\AppData\Roaming\Typora\typora-user-images\image-20200621165322626.png)]

margin:外边距

padding:内边距

border:边框

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>

<style>
    /*body有一个默认的外边距,在这里设置为0*/
    h2,body,a,div,p{
      margin: 0px;
        text-decoration: none;
    }

    h2{
        font-size: 20px;
        background: yellow;
        text-align: center;
    }

    #box{
        width: 400px;
        border: 1px solid red;
    }
    form{
        background: yellow;
    }
    /*solid 实线  dashed 虚线*/
    div:nth-of-type(1) input{
        border: 1px solid black;
    }
    div:nth-of-type(2) input{
        border: 1px dashed red;
    }

    /*margin border语法差不多
    外边距

    margin  0 0 0 0 上下左右


    */
    #name{
    /*上下左右*/
        margin-top: 100px;
        margin-bottom: 100px;
        margin-left: 20px;
        margin-right: 20px;
    }


</style>
<body>


<div id="box">
    <h2>会员登陆</h2>

    <form action="#">
        <div id="name">
            <span>用户名:</span>
            <input type="text">
        </div>
        <div  > <span>密码:</span>
            <input type="text"></div>
        <div><button>登陆</button></div>
    </form>
</div>








</body>
</html>
圆角边框
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        div:nth-of-type(1){
            width: 200px;
            border: 2px solid red;
            height: 200px;
            /*上下左右
                顺时针方向
                左上,右上 右下 左下

                圆圈:width=半径
            */


           /*border-radius: 100px 100px 0px 0px ;*/
            border-radius:200px 0 0 0 ;
        }
    img:nth-of-type(1){
        border-radius:240px ;
    }
        /*阴影*/
        div:nth-of-type(2){
            width: 200px;
            border: 2px solid red;
            height: 200px;
           /*阴影*/
            box-shadow: 10px 10px 100px yellow;
        }

        img:nth-of-type(2){
            /*居中,首先你必须是一个块元素,块元素有固定的宽度*/
            margin: 0 auto;
            border-radius:240px ;
            box-shadow: 10px 10px 100px yellow;
        }
    </style>
</head>
<body>
<div id="div1"></div>
<img src="image/2.jpg">

<div></div>
<div style="text-align: center">
<img src="image/2.jpg">
</div>
</body>
</html>
display
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

    <style>

        div ,body, ul ,li{
            margin: 0px;
        }

        /*
        block 块元素
        inline 行类元素
        inline-block 行类元素,但是可以在一行
        none 消失
        */
        #div{
            background: red;
        }
        p{

            width: 200px;
            height: 100px;
/*
            border: 1px  solid red;
*/
            display: inline-block;

            text-align: center;
        }



        /*span{*/
            /*width: 100px;*/
            /*height: 100px;*/
            /*border: 1px  solid red;*/
            /*display: inline-block;*/
        /*}*/

        ul{
            width: 100%;
            height: 100px;
            background: red;
        }
        p{
            display: inline;
        }

        li{
      /*      margin-top: 40px;*/
            list-style: none;
            display:  inline-block;
            margin-right: 33px;
            margin-top: 41px;


        }




    </style>


</head>
<body>


<ul>

    <li><a href="#">淘宝</a>/<a href="#">掏宝</a>/<a href="#">网上购物</a></li>
    <li><a href="#">网上交易</a>/<a href="#">在线交易</a>/<a href="#">交易市场</a></li>
    <li><a href="#">网上买</a>/<a href="#">网上卖</a>/<a href="#">购物网站</a></li>
    <li><a href="#">团购</a>/<a href="#">网上贸易</a>/<a href="#">安全购物</a></li>
    <li><a href="#">电子商务</a>/<a href="#">放心买</a>/<a href="#">供应</a></li>
    <li><a href="#">买卖信息</a>/<a href="#">一口价</a>/<a href="#">拍卖</a></li>

</ul>
</body>
</html>
浮动
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        /*
        float: right/left 右浮动 左浮动
        */

        /*
         clear: right右侧不允许浮动 left左侧不允许浮动 both 2侧不允许浮动
        */
        .div{
            width: 100px;
            height: 100px;
            background: red;
            display: inline-block;
            float: left;

            clear:both ;
        }
        p{
            width: 100px;
            height: 100px;
            background: red;
            display: inline-block;
            float: left;
            clear:both ;
        }


        label{
            width: 100px;
            height: 100px;
            background: red;
            display: inline-block;
            float: left;
            clear:both ;
        }

        /*父级元素的塌陷问题
       1.增加父级元素的高度
       2.增加一个空div,清除浮动
        
       3.overflow :hidden 隐藏 scroll
       4.在父类添加一个伪类
       */

        #fater{

            border: 1px solid black;
            width: 100%;
            overflow: hidden;

        }

    /*第四种方法     #fater:after{
            display: block;
            clear: both;
            content: "";
        }*/

    </style>


</head>
<body>

<div id="fater">
<div class="div">3123123</div>

<p>12312</p>
<label>12312231</label>

<!--
    <div class="clear"></div>
-->
</div>
</body>
</html>
相对定位
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>




        div{
            margin: 10px;
            padding: 5px;
            font-size: 12px;
            line-height: 10px;

        }
        #father{
                border: 1px solid black;

        }
        #first{
            border: 1px solid black;
            background: red;
            /*相对定位:相对于原来的位置.  position: relative;
            原来的位置会被保留
               */
            position: relative;
            top: -20px;
            left: 200px;

        }
        #second{
            border: 1px solid black;
            background: yellow;
            position: relative;
            right: 20px;
            bottom: 10px;
        }
        #third{
            border: 1px solid black;
            background: grey;

        }



    </style>



</head>
<body>

<div id="father">
    <div id="first">第一个</div>
    <div id="second">第二个</div>
    <div id="third">第三个</div>
</div>


</body>
</html>
绝对定位

定位:

1.没有父级元素的定位的前提下,相对于浏览器定位

2.假设父级元素存在定位,相对于父级元素进行偏移

3在父级元素类内移动。他如果不再标准的文档流中的话,原来的位置不会被保留。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        div{
            margin: 10px;
            padding: 10px;
        }

        #father{
            border: 2px solid black;
            position: relative;
        }

    #div1{
        height: 100px;
        text-align: center;
        background: red;
    }


    #div2{height: 100px;
        text-align: center;
        background: yellow;
        position: absolute;
        top: -100px;
    }


    #div3{height: 100px;
        text-align: center;
        background: green;}




    </style>



</head>
<body>


<div id="father">
    <div id="div1">1</div>
    <div id="div2">2</div>
    <div id="div3">3</div>
</div>

</body>
</html>
固定定位
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>


    <style>
        body{
            height: 1000px;
        }

        div:nth-of-type(1){
           width: 100px;
            height: 100px;
            background: red;
            position: absolute;
            left: 0px;
            bottom: 0px;
        }
        div:nth-of-type(2){/*固定定位 一直固定在坐下,不一会因为滚动条改变而改变*/
            width: 100px;
            height: 100px;
            background: yellow;
            position: fixed;
            /*上下左右*/


            left: 0px;
            bottom: 0px;
        }

    </style>
</head>
<body>
<div></div>
<div></div>
</body>
</html>
zindex
div,body,li,ul{
    margin: 0px;
    padding: 0px;
    list-style: none;
}

#father{
    font-family: 楷体;
    font-size: 12px;
    line-height: 25px;
    width: 200px;
    border: 1px solid black;
    overflow: hidden;
    position: relative;
}

#name,#back{
    width: 200px;
    height: 25px;
    position: absolute;
    top: 274px;
}

#name{
    color: white;
    z-index: 2;/*层级概念,默认是0层,可以修改。相当于在第二层*/
}
#back{
   background: black;
    /*背景透名度  opacity: 0.5;*/
    /*opacity: 0.5;*/
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值