css和html第三部分

/* 背景 */
            .box1{
            width: 500px;
            height: 500px;
            /* 
                background-color 设置背景颜色
             */
            background-color: #bfa;

            /* 
                background-image 设置背景图片 
                    - 可以同时设置背景图片和背景颜色,这样背景颜色将会成为图片的背景色
                    - 如果背景的图片小于元素,则背景图片会自动在元素中平铺将元素铺满
                    - 如果背景的图片大于元素,将会一个部分背景无法完全显示
                    - 如果背景图片和元素一样大,则会直接正常显示
                    
            */
            background-image: url("./img/1.png");

            /* 
                background-repeat 用来设置背景的重复方式
                    可选值:
                        repeat 默认值 , 背景会沿着x轴 y轴双方向重复
                        repeat-x 沿着x轴方向重复
                        repeat-y 沿着y轴方向重复
                        no-repeat 背景图片不重复
             */
            background-repeat: no-repeat;

            /*
                background-position 用来设置背景图片的位置
                    设置方式:
                        通过 top left right bottom center 几个表示方位的词来设置背景图片的位置
                            使用方位词时必须要同时指定两个值,如果只写一个则第二个默认就是center

                        通过偏移量来指定背景图片的位置:
                            水平方向的偏移量 垂直方向变量
            */
            /* background-position: center; */
            background-position: -50px 300px;



        }        .box1{
            width: 500px;
            height: 500px;
            overflow: auto;
            background-color: #bfa;
            background-image: url("./img/2.jpg");
            background-repeat: no-repeat;
            background-position: 0 0;
            padding: 10px;

            /*
                 设置背景的范围 
                    background-clip 
                        可选值:
                            border-box 默认值,背景会出现在边框的下边
                            padding-box 背景不会出现在边框,只出现在内容区和内边距
                            content-box 背景只会出现在内容区

                    background-origin 背景图片的偏移量计算的原点
                            padding-box 默认值,background-position从内边距处开始计算
                            content-box 背景图片的偏移量从内容区处计算
                            border-box 背景图片的变量从边框处开始计算
            */
            /* background-origin: border-box;
            background-clip: content-box; */

            /* 
                background-size 设置背景图片的大小
                    第一个值表示宽度 
                    第二个值表示高度
                    - 如果只写一个,则第二个值默认是 auto

                    cover 图片的比例不变,将元素铺满
                    contain 图片比例不变,将图片在元素中完整显示
            */
            background-size: contain;
            background: cover;
            /* 
                background-color
                background-image
                background-repeat
                background-position
                background-size
                background-origin
                background-clip
                background-attachment

                - backgound 背景相关的简写属性,所有背景相关的样式都可以通过该样式来设置
                    并且该样式没有顺序要求,也没有哪个属性是必须写的

                    注意:
                        background-size必须写在background-position的后边,并且使用/隔开
                            background-position/background-size

                        background-origin background-clip 两个样式 ,orgin要在clip的前边
                

            
             */




        }

        .box2{
            width: 300px;
            height: 1000px;
            background-image: url('./img/1.png');
            background-repeat: no-repeat;
            background-position: 100px 100px;

            /* 
            background-attachment
                - 背景图片是否跟随元素移动
                - 可选值:
                    scroll 默认值 背景图片会跟随元素移动
                    fixed 背景会固定在页面中,不会随元素移动
             */
            background-attachment: fixed;
        }

        .box3{
            border: 10px red double;
            padding: 50px;
            width: 500px;
            height: 500px;
            background: url('./img/2.jpg') #bfa  center center/contain border-box content-box no-repeat ;
        }


            /* 背景的渐变 */
            .box1{
                    width: 200px;
                    height: 200px;
                    /* background-color: #bfa; */
                    /* 
                        通过渐变可以设置一些复杂的背景颜色,可以实现从一个颜色向其他颜色过渡的效果
                        !!渐变是图片,需要通过background-image来设置

                        线性渐变,颜色沿着一条直线发生变化
                            linear-gradient()
                        

                            linear-gradient(red,yellow) 红色在开头,黄色在结尾,中间是过渡区域
                            - 线性渐变的开头,我们可以指定一个渐变的方向
                                to left
                                to right
                                to bottom
                                to top
                                deg deg表示度数
                                turn 表示圈

                            - 渐变可以同时指定多个颜色,多个颜色默认情况下平均分布,
                                也可以手动指定渐变的分布情况

                            repeating-linear-gradient() 可以平铺的线性渐变
                    */
                    
                    /* background-image: linear-gradient(red,yellow,#bfa,orange); */
                    /* background-image: linear-gradient(red 50px,yellow 100px, green 120px, orange 200px); */
                    background-image: repeating-linear-gradient(to right ,red, yellow 50px);

                }
                .box1{
                    width: 300px;
                    height: 300px;

                /* 
                    radial-gradient() 径向渐变(放射性的效果) */
                    /* 
                        默认情况下径向渐变的形状根据元素的形状来计算的
                            正方形 --> 圆形
                            长方形 --> 椭圆形
                            - 我们也可以手动指定径向渐变的大小
                            circle
                            ellipse

                            - 也可以指定渐变的位置
                            - 语法:
                                radial-gradient(大小 at 位置, 颜色 位置 ,颜色 位置 ,颜色 位置)
                                    大小:
                                        circle 圆形
                                        ellipse 椭圆
                                        closest-side 近边  
                                        closest-corner 近角
                                        farthest-side 远边
                                        farthest-corner 远角

                                    位置:
                                        top right left center bottom
                                        


                    */

                    background-image: radial-gradient(farthest-corner at 100px 100px, red , #bfa)
                }


/* 表格的样式 */
        table{
            width: 50%;
            border: 1px solid black;
            margin: 0 auto;

            /* border-spacing: 指定边框之间的距离 */
            /* border-spacing: 0px; */

            /* border-collapse: collapse; 设置边框的合并 */
            border-collapse: collapse;
        }

        td{
            border: 1px solid black;
            height: 100px;
            /* 默认情况下元素在td中是垂直居中的 可以通过 vertical-align 来修改*/
            vertical-align:middle;
            text-align: center; 
        }

        /* 
            如果表格中没有使用tbody而是直接使用tr,
                那么浏览器会自动创建一个tbody,并且将tr全都放到tbody中
                tr不是table的子元素
         */
        tbody > tr:nth-child(odd){
            background-color: #bfa;
        }

        .box1{
            width: 300px;
            height: 300px;
            background-color: orange;

            /* 将元素设置为单元格 td  */
            display: table-cell;
            vertical-align: middle;

        }

        .box2{
            width: 100px;
            height: 100px;
            background-color: yellow;
            margin: 0 auto;
        }

/* 动画 */
        .box2{
            background-color: #bfa;
            transition-property: height , width;
            transition-duration: 100ms, 2s;
            transition-timing-function: steps(2, start);
            transition-delay: 2s;
            /* margin-left: auto; */
            /* transition:all 2s; */
   
   
   
    /* 
        过渡(transition)
                    - 通过过渡可以指定一个属性发生变化时的切换方式
                    - 通过过渡可以创建一些非常好的效果,提升用户的体验
             */

             /* 
             transition-property: 指定要执行过渡的属性  
                多个属性间使用,隔开 
                如果所有属性都需要过渡,则使用all关键字
                大部分属性都支持过渡效果,注意过渡时必须是从一个有效数值向另外一个有效数值进行过渡
             */
            /* transition-property: height , width; */
            /* transition-property: all; */

             /*
              transition-duration: 指定过渡效果的持续时间
                时间单位:s 和 ms  1s = 1000ms
              */
             /* transition-duration: 100ms, 2s; */
             /* transition-duration: 2s; */

             /* 
             transition-timing-function: 过渡的时序函数
                指定过渡的执行的方式  
                可选值:
                    ease 默认值,慢速开始,先加速,再减速
                    linear 匀速运动
                    ease-in 加速运动
                    ease-out 减速运动
                    ease-in-out 先加速 后减速
                    cubic-bezier() 来指定时序函数
                        https://cubic-bezier.com
                    steps() 分步执行过渡效果
                        可以设置一个第二个值:
                            end , 在时间结束时执行过渡(默认值)
                            start , 在时间开始时执行过渡
             */
             /* transition-timing-function: cubic-bezier(.24,.95,.82,-0.88); */
             /* transition-timing-function: steps(2, start); */


             /* 
             transition-delay: 过渡效果的延迟,等待一段时间后在执行过渡  
             */
             /* transition-delay: 2s; */
             

             /* transition 可以同时设置过渡相关的所有属性,只有一个要求,如果要写延迟,则两个时间中第一个是持续时间,第二个是延迟 */
             transition:2s margin-left 1s cubic-bezier(.24,.95,.82,-0.88);
             transition-timing-function: cubic-bezier(1, 0, 0, 1);
             transition: 2s margin-left 2s cubic-bezier(0.6, -0.28, 0.735, 0.045);
        }

        .box2{
            background-color: #bfa;
            animation-name: test;
            animation-duration: 4s;
            animation-delay: 2s;
            animation-iteration-count: 1;
            animation-direction: alternate-reverse;
            animation-play-state: paused;
            animation-fill-mode: both;



            animation-name: test;
            animation-timing-function: cubic-bezier(0.6, -0.28, 0.735, 0.045);
            animation-fill-mode: both;
            animation-delay: 0s;
            animation-play-state: running;
            animation-direction: alternate;
            animation-duration: 0s;
            /* 设置box2的动画 */
            /* animation-name: 要对当前元素生效的关键帧的名字 */
            /* animation-name: test; */

            /* animation-duration: 动画的执行时间 */
            /* animation-duration: 4s; */

            

            /* 动画的延时 */
            /* animation-delay: 2s; */

            /* animation-timing-function: ease-in-out; */

            /* 
            animation-iteration-count 动画执行的次数 
                可选值:
                    次数
                    infinite 无限执行
            */
            /* animation-iteration-count: 1; */

            /*
             animation-direction
                指定动画运行的方向
                    可选值:
                    normal 默认值  从 from 向 to运行 每次都是这样 
                    reverse 从 to 向 from 运行 每次都是这样 
                    alternate 从 from 向 to运行 重复执行动画时正向执行
                    alternate-reverse 从 to 向 from运行 重复执行动画时反向执行

            */
            /* animation-direction: alternate-reverse; */

            /* 
                animation-play-state: 设置动画的执行状态 
                可选值:
                    running 默认值 动画执行
                    paused 动画暂停
            */
            /* animation-play-state: paused; */

            /* 
            animation-fill-mode: 动画的填充模式
                可选值:
                    none 默认值 动画执行完毕元素回到原来位置
                    forwards 动画执行完毕元素会停止在动画结束的位置
                    backwards 动画延时等待时,元素就会处于开始位置
                    both 结合了forwards 和 backwards
            */
            /* animation-fill-mode: both; */
            animation: test 2s 2 1s alternate;

            
        }

        .box1:hover div{
            animation-play-state: paused;
        }




        /* 
        动画
            动画和过渡类似,都是可以实现一些动态的效果,
                不同的是过渡需要在某个属性发生变化时才会触发
                动画可以自动触发动态效果
                
            设置动画效果,必须先要设置一个关键帧,关键帧设置了动画执行每一个步骤
        */
        @keyframes test {
            /* from表示动画的开始位置 也可以使用 0% */
            from{
                margin-left: 0;
                background-color: orange;
            } 

            /* to动画的结束位置 也可以使用100%
            在这中间可以夹杂20%.......等等百分值以控制动画状态
            
            eg:
             创建小球下落的动画 
            @keyframes ball { 
            from{
                margin-top: 0;
            }

            to{
                margin-top: 400px;
            }

             2                                    to{
                margin-top: 400px;
                animation-timing-function: ease-in;
            }

            40%{
                margin-top: 100px;
            }

            80%{
                margin-top: 200px;
            } */
            to{
                background-color: red;
                margin-left: 700px;
            }
        }

/* 变形 */

       
        .box1{
            width: 200px;
            height: 200px;
            background-color: #bfa;
            margin: 0 auto;
            margin-top: 200px;

          /* 
                变形就是指通过CSS来改变元素的形状或位置
                -   变形不会影响到页面的布局
                - transform 用来设置元素的变形效果
                    - 平移:
                        translateX() 沿着x轴方向平移
                        translateY() 沿着y轴方向平移
                        translateZ() 沿着z轴方向平移
                            - 平移元素,百分比是相对于自身计算的
            */
            /* transform: translateY(-100px); */
            transform: translateX(100%);
            transform: translateX();
        }

        /* .box2{
            width: 200px;
            height: 200px;
            background-color: orange;
            margin: 0 auto;
        } */

        .box3{
            background-color: orange;
            position: absolute;
            /* 
                这种居中方式,只适用于元素的大小确定
            top: 0;
            left: 0;
            bottom: 0;
            right: 0;
            margin: auto; */

            left: 50%;
            top: 50%;
            transform: translateX(-50%) translateY(-50%);
          
        }

        .box4, .box5{
            width: 220px;
            height: 300px;
            background-color: #fff;
            float: left;
            margin: 0 10px;
            transition:all .3s;
        }

        .box4:hover,.box5:hover{
            transform: translateY(-4px);
            box-shadow: 0 0 10px rgba(0, 0, 0, .3)
        }




        html{
            /* 设置当前网页的视距为800px,人眼距离网页的距离 
            如果要设置z轴的平移,就必须要设置这个视距*/
            perspective: 800px;
        }

        body{
            border: 1px red solid;
            background-color: rgb(241, 241, 241);
        }
        .box1{
            width: 200px;
            height: 200px;
            background-color: #bfa;
            margin: 200px auto;
            /* 
                z轴平移,调整元素在z轴的位置,正常情况就是调整元素和人眼之间的距离,
                    距离越大,元素离人越近
                z轴平移属于立体效果(近大远小),默认情况下网页是不支持透视,如果需要看见效果
                    必须要设置网页的视距
            */

            transition:2s;
        }

        body:hover .box1{
            transform: translateZ(800px);
        }



        body:hover .box1{

            /*
                通过旋转可以使元素沿着x y 或 z旋转指定的角度
                    rotateX()
                    rotateY()
                    rotateZ()
            */
            /* transform: rotateZ(.25turn); */
            /* transform: rotateY(180deg) translateZ(400px); */
            /* transform: translateZ(400px) rotateY(180deg) ; */
            transform: rotateY(180deg);
            /* 是否显示元素的背面 */
            backface-visibility: hidden;
            backface-visibility: initial;
            transform: rotateX(10deg);

            }




            .box1{
                width: 100px;
                height: 100px;
                background-color: #bfa;
                transition:2s;
                margin: 100px auto;
                transform-origin: 0 0;

                /* 变形的原点 默认值 center*/
                /* transform-origin:20px 20px;  */
            }
            .box1:hover{
                /* 
                    对元素进行缩放的函数:
                        scaleX() 水平方向缩放
                        scaleY() 垂直方向缩放
                        scale() 双方向的缩放
                */
                transform:scale(1.2)
            }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值