使用css设置DIV固定悬浮

照旧先阐述问题,项目中需要这样一个功能。有一个按钮的设计是需要一直呆在页面右上角 。

举一反三,实现右下、左上、左上、中间的悬浮效果。

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<title>CSS实现DIV悬浮</title>
<style type="text/css">
    /*DIV样式*/
    div{
        width:100%;
        height:50px;
        border:0px;
        padding:5px 5px 5px 50px;
        position:fixed;
    }
    /*右上角*/
    .topRight{
        top:0;
        right:0;
    }
    /*左上角*/
    .topLeft{
        top:0;
        left:0;
    }
    /*右下角*/
    .bottomRight{
        bottom:0px;
        right:0px;
    }
    /*左下角*/
    .bottomLeft{
        bottom:0px;
        right:0px;
    }
    /*屏幕中间,实际应用中留出DIV的大小来*/
    .center{
        right:50%;
        top: 50%;
    }
</style>
</head>
<body>
    <div class="topRight">
         <a class="layui-btn" href="javascript:;" style="float:right;">右上角</a>
    </div>
    <div class="topLeft">
         <a class="layui-btn" href="javascript:;" style="float:right;">左上角</a>
    </div>
    <div class="bottomRight">
         <a class="layui-btn" href="javascript:;" style="float:right;">右下角</a>
    </div>
    <div class="bottomLeft">
         <a class="layui-btn" href="javascript:;" style="float:right;">左下角</a>
    </div>
    <div class="center">
         <a class="layui-btn" href="javascript:;" style="float:right;">当中央</a>
    </div>
</body>
</html>

 

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值