照旧先阐述问题,项目中需要这样一个功能。有一个按钮的设计是需要一直呆在页面右上角 。
举一反三,实现右下、左上、左上、中间的悬浮效果。
<!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>