位置:首页 » 文章/教程分享 » HTML 固定div于页面固定位置实现悬浮按钮

本文介绍因为页面过长,业务希望将按钮悬浮于页面上,不要一下拉就盖掉操作按钮的一种实现方式,供大家参考。

代码如下:

<div id="dg" style="z-index: 9999; position: fixed ! important; right: 0px; top: 0px;">
<table width=""100% style="position: absolute; width:260px; right: 0px; top: 0px;">
//table 内部控件代码
</table>
</div>

div position参数设置为fixed 其相对于浏览器为绝对位置,通过设置right和top将div固定在右上角。

table position参数设置为absolute,其相对于第一层div绝对定位,通过设置right和top将table固定在div容器的右上角。