1.图标被覆盖时会变大1.2倍,点击后下面的图标显现出来

2.HTML代码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>按钮</title>
    <link href="https://cdn.bootcdn.net/ajax/libs/font-awesome/5.13.0/css/all.css" rel="stylesheet">
    <link rel="stylesheet" href="style.css">
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.js"></script>
</head>
<body>
    <div class="middle">
        <div class="sm-container">
            <i class="show-btn fas fa-user"></i>
            <div class="sm-menu">
                <a href="#"><i class="fab fa-facebook-f"></i></a>
                <a href="#"><i class="fab fa-twitter"></i></a>
                <a href="#"><i class="fab fa-instagram"></i></a>
                <a href="#"><i class="fab fa-youtube"></i></a>
                <a href="#"><i class="fab fa-whatsapp"></i></a>
            </div>
        </div>
    </div>

    <script>
        $(".show-btn").click(function(){
            $(".sm-menu").fadeToggle("fast");
        });
    </script>
    
</body>
</html>

3.CSS代码


body{
    margin: 0;
    padding: 0;
    background: #9c88ff;
}

.middle{
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%,-50%);
}

.sm-container{
    text-align: center;
}

.sm-container i{
    color: #f5f6fa;
    padding: 20px;
    font-size: 20px;
    cursor: pointer;
    transition: 0.4s;
}

.sm-container i:hover{
    /* 按钮被覆盖后会变大1.2倍 */
    transform: scale(1.2);
}

.sm-menu{
    background: #487eb0;
    position: absolute;
    border-radius: 8px;
    /* 元素在页面上消失 */
    display: none;
}

.sm-menu::before{
    content: "";
    width: 10px;
    height: 10px;
    background: #487eb0;
    position: absolute;
    top: -5px;
    left: 50%;
    transform: translateX(-50%) rotate(45deg);
}