css怎么设置悬浮效果


本文摘自PHP中文网,作者青灯夜游,侵删。

css设置悬浮效果的方法:首先给元素添加“position: fixed;”样式,固定元素的位置,让元素悬浮在页面中,不随浏览器窗口的滚动条滚动而变化;然后使用top、bottom、left、right属性设置元素的悬浮位置即可。

本教程操作环境:windows7系统、CSS3&&HTML5版、Dell G3电脑。

css设置悬浮效果(固定位置)

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

<!DOCTYPE html>

<html>

 

    <head>

        <meta charset="utf-8" />

        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />

        <title>DIV悬浮示例-纯CSS实现</title>

 

        <style type="text/css">

            /*设置了高度,可以上下滚动*/

             

            body {

                height: 1800px;

                background: #dddddd;

            }

            /*div通用样式*/

             

            div {

                background: #1a59b7;

                color: #ffffff;

                overflow: hidden;

                z-index: 9999;

                position: fixed;  /*DIV悬浮(固定位置)*/

                padding: 5px;

                text-align: center;

                width: 175px;

                height: 22px;

                border-bottom-left-radius: 4px;

                border-bottom-right-radius: 4px;

                border-top-left-radius: 4px;

                border-top-right-radius: 4px;

            }

            /*右上角*/

             

            div.right_top {

                right: 10px;

                top: 10px;

            }

            /*右下角*/

             

            div.right_bottom {

                right: 10px;

                bottom: 10px;

            }

            /*屏幕中间*/

             

            div.center_ {

                right: 45%;

                top: 50%;

            }

            /*左上角*/

             

            div.left_top {

                left: 10px;

                top: 10px;

            }

            /*左下角*/

             

            div.left_bottom {

                left: 10px;

                bottom: 10px;

            }

        </style>

 

    </head>

 

    <body>

        <div class="right_top"> 我是右上角悬浮的div</div>

        <div class="right_bottom"> 我是右下角悬浮的div</div>

        <div class="center_"> 我是屏幕中间悬浮的div</div>

        <div class="left_top"> 我是左上角悬浮的div</div>

        <div class="left_bottom"> 我是左下角悬浮的div</div>

    </body>

 

</html>

效果图:

阅读剩余部分

相关阅读 >>

详解css3+svg滤镜实现不规则边框的方法

css align-self属性怎么用

分享div+css前端命名的规则

怎样实现meta标签中的viewport来控制设备屏幕的css属性

css如何实现圆角内凹效果

react中如何引入css样式

深入浅析css中的z-index

css a hover 不变色怎么办

css如何插入图片

css sprite优缺点有哪些

更多相关阅读请进入《css》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...