About transition effects

Function: Let the style of the element change slowly, often used with hover to enhance the interactive experience of the web page.
Property name: transition.

111
important point:

  1. Transition needs: The default state and the hover state have different styles to have a transition effect.

  2. The transition attribute is added to the element itself that needs to be transitioned (whoever changes will add the transition attribute)

  3. The transition property is set in different states, and the effect is different

① Set to the default state, there is a transition effect when the mouse moves in and out

② Set the hover state, there is a transition effect when the mouse is moved in, and there is no transition effect when the mouse is moved out.

Case: Box width changed from 200px to 600px

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        /* 过渡配合hover使用, 谁变化谁加过渡属性 */
        .box {
    
    
            width: 200px;
            height: 200px;
            background-color: pink;
            /* 宽度200, 悬停的时候宽度600,背景色也变化程红色 花费1秒钟 */
            /* transition: width 1s, background-color 2s; */
            /* 如果变化的属性多, 直接写all,表示所有 */
            transition: all 1s;
        }

        .box:hover {
    
    
            width: 600px;
            background-color: red;
        }
    </style>
</head>
<body>
    <div class="box"></div>
</body>
</html>

Guess you like

Origin blog.csdn.net/qq_42931285/article/details/123949698