五、过渡transition、平移translate 旋转rotate 缩放scale、动画animation、字体图标

 241017

1. 过渡 transition

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>过渡</title>
    <style>
        /* 
            transition复合属性,多个属性值用空格隔开
            可以为一个元素在不同状态之间切换的时候添加过渡效果
            transition: all 1s;
        */
        div{
            width: 100px;
            height: 100px;
            background-color: orangered;
            /* transition: width 1s,height 1s; */
            transition: all 1s;
        }
        div:hover{
            width: 200px;
            height: 200px;
            background-color: lightblue;
        }
    </style>
</head>
<body>
    <div></div>
</body>
</html>

2. 平面转换

2.1 平移 translate

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>平移</title>
    <style>
        /* 
            平移translate
            属性值百分比,参照自身尺寸计算平移结果
            水平方向平移:translateX
            垂直方向平移:translateY
            translate3D & translateZ 3D效果

            正值表示向右或向下移动,负值表示向左或向上移动。
        */
        div{
            width: 100px;
            height: 100px;
            background-color: orangered;

            /* translate属性值数值之间加逗号!!! */
            transform: translate(200px,30px);
            /* 一个值 水平方向平移 */
            transform: translate(50px);

            /* 单水平方向平移 */
            transform: translateX(30px);
            /* 单垂直方向平移 */
            transform: translateY(20px);
        }
    </style>
</head>
<body>
    <div></div>
</body>
</html>

2.2 旋转 rotate

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>旋转</title>
    <style>
        div{
            width: 100px;
            height: 100px;
            background-color: orangered;
            transition: 1s;
        }
        div:hover{
            /* rotate 正数顺时针旋转,负数逆时针 */
            transform: rotate(60deg); 
        }
    </style>
</head>
<body>
    <div></div>
</body>
</html>

2.3 多重转换

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>多重转换</title>
    <style>
        /* 一个标签具有多重转换效果 */
        div{
            width: 900px;
            height: 100px;
            background-color: orangered;
            margin: 0 auto;
        }
        img{
            width: 100px;
            aspect-ratio: 1;
            
            /* 过渡 自带变化曲线 先快后慢 */
            transition: all 2s;
        }
        /* 鼠标悬停在div区域内,img动 */
        div:hover img{
            /* 先平移固定了坐标轴方向,再旋转时以平移轴向为准 */
            transform: translate(800px) rotate(360deg);
            /* 旋转会改变坐标轴向 */
            /* transform: rotate(360deg) translate(800px); */
        }
    </style>
</head>
<body>
    <div>
        <img src="./tyre.png" alt="">
    </div>
</body>
</html>

2.4 缩放 scale

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>缩放</title>
    <style>
        /* 
            缩放比取值大于1表示放大,取值小于1表示缩小
            通常只为scale()设置一个值,表示X轴和Y轴等比例缩放
        */
        div{
            width: 100px;
            height: 100px;
            background-color: orangered;
            transition: 1s;
        }
        div:hover{
            /* X、Y缩放比例相同 */
            transform: scale(0.8); 
            /* X、Y设置不同缩放比例 */
            transform: scale(1,0.8);
        }
    </style>
</head>
<body>
    <div></div>
</body>
</html>

3. 动画 animation

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>动画</title>
    <style>
        /* 
            动画:实现多个状态间的变化过程
        */
        div{
            width: 100px;
            height: 100px;
            background-color: orangered;

            /* 调用动画 animation:动画名称 动画时长 */
            /* animation: 动画名称 动画花费时长 速度曲线 延迟时间 重复次数 动画方向 执行完毕时的状态; */
            /* 取值不分先后顺序 */
            /* infinite无限循环 */
            animation: change 2s infinite;
            /* 第二个时间为延迟时间 */
            /* 数字为动画重复次数 */
            /* linear 速度曲线的匀速运动 */
            /* alternate往返运动 */
            /* forwards 动画结束状态为完毕时效果 */
            animation: change 3s 1s 3;
        }

        /* 定义动画方法一 */
        @keyframes change {
            from{
                width: 100px;
            }
            to{
                width: 800px;
            }
        }

        /* 定义动画方法二 */
        /*  */
        /* @keyframes change {
            20%{width: 200px;}
            50%{width: 500px;}
            80%{width: 700px;}
            100%{width: 1000px;}
        } */
    </style>
</head>
<body>
    <div></div>
</body>
</html>

4. 案例-风车

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>风车</title>
    <style>
        @keyframes donghua{
            from{
                width: 200px;
                height: 200px;
            }
            to{
                /* width: 500px;
                height: 500px; */
                transform: translate(300px) scale(2) rotate(360deg);
            }
        }
        .fengche{
            margin: 100px auto;
            width: 200px;
            height: 200px;
            /* background-color: lightgray; */
            display: flex;
            flex-wrap: wrap;
            position: relative;
            animation: donghua 5s infinite;
            /* transition: 5s; */
        }

        /* .fengche:hover{ */
            /* transform: translate(800px) rotate(360deg); */
            /* transform: rotate(360deg) scale(1.5);   */
        /* } */

        .fengche div{
            position: absolute;
        }
        .lt{
            width: 100px;
            height: 50px;
            background-color: red;
            left: 0;
            top: 50px;
            border-radius: 50px 50px 0 0;
        }
        .rt{
            width: 50px;
            height: 100px;
            background-color: orange;
            left: 100px;
            top: 0;
            border-radius: 0 50px 50px 0;
        }
        .lb{
            width: 50px;
            height: 100px;
            background-color: yellow;
            left: 50px;
            top: 100px;
            border-radius: 50px 0 0 50px;
        }
        .rb{
            width: 100px;
            height: 50px;
            background-color: green;
            left: 100px;
            top: 100px;
            border-radius: 0 0 50px 50px;
        }
    </style>
</head>
<body>
    <div class="fengche">
        <div class="lt"></div>
        <div class="rt"></div>
        <div class="lb"></div>
        <div class="rb"></div>
    </div>
</body>
</html>

5. 字体图标

字体图标:展示的是图标本质是字体

作用:在网页中添加简单的、颜色单一的小图标

优点:

  • 灵活性:灵活地修改样式,例如:尺寸、颜色等
  • 轻量级:体积小、渲染快、降低服务器请求次数
  • 兼容性:几乎兼容所有主流浏览器
  • 使用方便:先下载再使用
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>字体图标</title>
    <link rel="stylesheet" href="./font_4714743_wegxds146em/iconfont.css">
    <style>
        .iconfont{
            /* iconfont优先级高于span */
            font-size: 50px;
            color: aqua;
        }
    </style>
</head>
<body>
    <!-- 使用字体图标 两个类名 -->
    <!-- iconfont 字体的公共样式,专门用来指定字体文件 -->
    <!-- icon-xxxx 具体图标的名字 -->
    <span class="iconfont icon-shouye-zhihui"></span>
</body>
</html>
@font-face {
  font-family: "iconfont"; /* Project id 4714743 */
  src: url('iconfont.woff2?t=1729151189668') format('woff2'),
       url('iconfont.woff?t=1729151189668') format('woff'),
       url('iconfont.ttf?t=1729151189668') format('truetype');
}

.iconfont {
  /* 字体 */
  font-family: "iconfont" !important;
  font-size: 16px;
  font-style: normal;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.icon-xihuan:before {
  content: "\e61d";
}

.icon-shouye-zhihui:before {
  content: "\e61e";
}

.icon-gerenzhongxin-zhihui:before {
  content: "\e61f";
}

6. 案例-华为新闻

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>241018华为新闻_课上跟练</title>
    <link rel="stylesheet" href="./iconfont/iconfont.css">
    <style>
        /* 布局 从外到内 先大后小 写一个盒子写一个css样式 */
        *{
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        /* 总区域 版心居中 spacebetween布局 */
        .box{
            width: 1000px;
            height: 211px;
            /* background-color: lightcyan; */
            margin: 50px auto;
            display: flex;
            justify-content: space-between;
        }
        /* 单个新闻大块 */
        .news{
            width: 300px;
            height: 100%;
            /* background-color: lightcoral; */
            position: relative;
            /* 给底块加溢出隐藏效果 */
            overflow: hidden;
        }
        /* 新闻图设置 */
        img{
            width: 300px;
            transition: all 0.5s;
        }
        /* 新闻介绍文字 */
        .txt{
            width: 300px;
            position: absolute;
            bottom: -60px;
            padding: 20px;
            color: white;
            /* background-color: lightgreen; */
            transition: all 0.5s;
        }
        h3{
            margin-bottom: 40px;
        }
        .iconfont{
            color: red;
            vertical-align: middle;
            font-size: 20px;
            font-weight: 700;
        }

        /* 悬停时灰色底色块 */
        .touming{
            width: 100%;
            height: 100%;
            background-color: #5f53532f;
            position: absolute;
            top: 0;
            /* 透明度opacity 0完全透明 1不透明*/
            opacity: 0;
            transition: all 0.5s;
        }
        .news:hover img{
            transform: scale(1.2);
        }
        .news:hover .txt{
            bottom: 0;
        }
        .news:hover .touming{
            opacity: 1;
        }
        
    </style>
</head>
<body>
    <div class="box">
        <div class="news">
            <!-- 新闻图片 -->
            <img src="./images/product.jpeg" alt="">

            <!-- 介绍文字 -->
            <div class="txt">
                <h4>产品</h4>
                <h3>OceanStorPacific海量存储斩获2021 Interop金奖</h3>
                <p>
                    <span>了解更多</span>
                    <i class="iconfont icon-arrow-right"></i>
                </p>
            </div>
            <!-- 遮罩层 透明阴影图片 -->
            <div class="touming"></div>
        </div>


        <div class="news">
            <img src="./images/product.jpeg" alt="">
            <div class="txt">
                <h4>产品</h4>
                <h3>OceanStorPacific海量存储斩获2021 Interop金奖</h3>
                <p>
                    <span>了解更多</span>
                    <i class="iconfont icon-arrow-right"></i>
                </p>
            </div>
            <div class="touming"></div>
        </div>
        <div class="news">
            <img src="./images/product.jpeg" alt="">
            <div class="txt">
                <h4>产品</h4>
                <h3>OceanStorPacific海量存储斩获2021 Interop金奖</h3>
                <p>
                    <span>了解更多</span>
                    <i class="iconfont icon-arrow-right"></i>
                </p>
            </div>
            <div class="touming"></div>
        </div>
    </div>
</body>
</html>

CSS3的变形(transform)、过渡(transition)、动画(animation)是CSS3中非常重要的特性,可以为网页设计带来更加丰富的交互效果和视觉体验。 1. 变形(transform) 变形是指通过CSS3中的transform属性对元素进行平移旋转缩放、倾斜等操作,从而改变元素的形状和位置。具体的变形方式包括: 平移translate):移动元素的位置。 旋转rotate):以元素中心点为轴心进行旋转缩放scale):缩放元素的大小。 倾斜(skew):倾斜元素。 矩阵变形(matrix):通过矩阵变换实现复杂的变形效果。 示例代码: ``` div { transform: translate(50px, 50px); } ``` 2. 过渡(transition) 过渡是指在元素属性改变时,通过CSS3中的transition属性设置过渡时间和过渡效果,从而实现平滑的转换效果。具体的过渡方式包括: 过渡时间(transition-duration):设置过渡动画的时间,单位可以是秒(s)或毫秒(ms)。 过渡效果(transition-timing-function):设置过渡效果,常用的有linear、ease-in、ease-out、ease-in-out等。 过渡属性(transition-property):设置需要过渡的属性,可以是单个属性或多个属性。 过渡延迟(transition-delay):设置过渡动画的延迟时间。 示例代码: ``` div { transition: all 1s ease-in-out; } ``` 3. 动画(animation) 动画是指通过CSS3中的animation属性对元素进行动画效果的设置。具体的动画方式包括: 关键帧动画(@keyframes):定义一组动画序列,可以设置元素在不同时间点上的样式。 动画时间(animation-duration):设置动画持续时间,单位可以是秒(s)或毫秒(ms)。 动画速度(animation-timing-function):设置动画速度,常用的有linear、ease-in、ease-out、ease-in-out等。 动画延迟(animation-delay):设置动画延迟时间。 动画方向(animation-direction):设置动画播放方向,可以是正方向(normal)、反方向(reverse)、交替播放(alternate)等。 动画次数(animation-iteration-count):设置动画播放次数,可以是无限次(infinite)。 示例代码: ``` div { animation: myanimation 2s ease-in-out infinite; } @keyframes myanimation { 0% { transform: scale(1); } 50% { transform: scale(1.5); } 100% { transform: scale(1); } } ``` 以上就是CSS3中变形、过渡动画的基本介绍和示例代码,希望对你有所帮助。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值