html css 返回顶部按钮位置怎么固定?

html-css017

html css 返回顶部按钮位置怎么固定?,第1张

可以使用相当于浏览器定位。css样式中写入:\x0d\x0a{position: fixed\x0d\x0a right: 20px\x0d\x0a bottom: 100px}相当于浏览器右边20px,浏览器底部100px的距离的定位。\x0d\x0afixed总是以body为定位时的对象,总是根据浏览器的窗口来进行元素的定位,通过"left"、 "top"、 "right"、 "bottom" 属性进行定位。

window.onscroll=function(){

var autoheight=document.body.scrollTop||document.documentElement.scrollTop

if(autoheight>76){

$("#index-left").css("position","fixed")

$("#index-left").css("top",0)

$("#index-left").css("left",0)

}

else{

$("#index-left").css("position","absolute")

}

}你那个有兼容 我这个是我线上使用的

将底部的内容定位到顶部,只要在css层上面加上一个浮动,将定位至top设置成0即可。说明如下:

position:absolute(将对象浮动)

top:0(将对象定位对顶部)

整体css示范如下:

<div style="position:absolute top:0 width:100% height:50px background:#000 color:#FFF text-align:center">内容顶部</div>

如要将内容放至底部,只需将top:0修改成bottom:0即可,整体css未范如下:

<div style="position:absolute bottom:0 width:100% height:50px background:#000 color:#FFF text-align:center">内容底部</div>

希望我的回答能令你满意!