广告位联系
返回顶部
分享到

CSS实现鼠标悬停在div上出现抬起元素的效果

css 来源:互联网 作者:佚名 发布时间:2024-06-27 21:55:52 人浏览
摘要

CSS实现鼠标悬停在div上出现抬起元素的效果 如图所示,左侧为正常样式,右侧为添加效果后的样式 只需要给div添加以下class样式,主要实现效果在:hover里面 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 .comp

CSS实现鼠标悬停在div上出现抬起元素的效果

如图所示,左侧为正常样式,右侧为添加效果后的样式

只需要给div添加以下class样式,主要实现效果在&:hover里面

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

.component-item {

  display: flex;

  align-items: center;

  width: 50px;

  height: 50px;

  border: 1px solid #f0f0f0;

  border-radius: 4px;

  box-sizing: border-box;

  overflow: hidden;

  margin-bottom: 5px;

  margin-left: 15px;

  &:hover {

    cursor: move;

    box-shadow: 0 4px 16px rgb(0, 0, 0);

  }

}

CSS3:鼠标悬停效果

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

<!DOCTYPE html>

<html>

    <head>

        <meta charset="utf-8">

        <title>Hello H5</title>

        <style>

            * {

                margin: 0;

                padding: 0;

                box-sizing: border-box;

            }

            body {

                height: 100vh;

                background: #d6e5e7;

                display: flex;

                align-items: center;

                justify-content: center;

            }

            .nav {

                display: flex;

                align-items: center;

                position: relative;

                z-index: 1;

            }

            .item {

                width: 70px;

                height: 70px;

                display: flex;

                align-items: center;

                justify-content: center;

                flex-direction: column;

                cursor: pointer;

                position: relative;

                z-index: 1;

            }

            img {

                transform: scale(1);

                transition: .5s;

            }

            span {

                position: absolute;

                bottom: 5px;

                font-size: 12px;

                color: #fff;

                opacity: 0;

                transition: .5s;

            }

            .active img {

                transform: scale(.8);

            }

            .active span {

                opacity: 1;

            }

            .bg {

                width: 70px;

                height: 70px;

                border-radius: 10px;

                position: absolute;

                left: 0;

                top: 0;

                z-index: 0;

                transition: .5s;

            }

            .active:nth-child(1)~.bg {

                transform: translateX(calc(70px*0));

                background: #f53b57;

                box-shadow: 0 10px 15px #f53b57;

            }

            .active:nth-child(2)~.bg {

                transform: translateX(calc(70px*1));

                background: #5d62fb;

                box-shadow: 0 10px 15px #5d62fb;

            }

            .active:nth-child(3)~.bg {

                transform: translateX(calc(70px*2));

                background: #05c46b;

                box-shadow: 0 10px 15px #05c46b;

            }

            .active:nth-child(4)~.bg {

                transform: translateX(calc(70px*3));

                background: #0fbcf9;

                box-shadow: 0 10px 15px #0fbcf9;

            }

            .active:nth-child(5)~.bg {

                transform: translateX(calc(70px*4));

                background: #ffa801;

                box-shadow: 0 10px 15px #ffa801;

            }

        </style>

    </head>

    <body>

        <div class="nav">

            <div class="item active">

                <img src="home.png">

                <span>home</span>

            </div>

            <div class="item">

                <img src="goods.png">

                <span>goods</span>

            </div>

            <div class="item">

                <img src="cart.png">

                <span>cart</span>

            </div>

            <div class="item">

                <img src="mine.png">

                <span>mine</span>

            </div>

            <div class="item">

                <img src="setup.png">

                <span>setup</span>

            </div>

            <div class="bg"></div>

        </div>

    </body>

    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>

    <script type="text/javascript">

        $('.nav').on('click', '.item', function(event) {

            var index = $(this).index(); //获取到点击的.nav下,item的索引

            $(".nav .item").eq(index).addClass("active").siblings().removeClass("active"); //点击项高亮显示

        });

    </script>

</html>

在这里插入图片描述


版权声明 : 本文内容来源于互联网或用户自行发布贡献,该文观点仅代表原作者本人。本站仅提供信息存储空间服务和不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权, 违法违规的内容, 请发送邮件至2530232025#qq.cn(#换@)举报,一经查实,本站将立刻删除。
原文链接 :
相关文章
  • 本站所有内容来源于互联网或用户自行发布,本站仅提供信息存储空间服务,不拥有版权,不承担法律责任。如有侵犯您的权益,请您联系站长处理!
  • Copyright © 2017-2022 F11.CN All Rights Reserved. F11站长开发者网 版权所有 | 苏ICP备2022031554号-1 | 51LA统计