<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>css固定定位</title> <style> #back{ width: 100px; height: 100px; background-color: #FF6500; text-align: center; line-height: 100px;(line-height=height垂直居中) position: fixed;(固定定位) bottom: 20px; right: 20px; z-index: 1000;(使目标悬浮在界面上,置于上层,数字可调整) } </style> </head> <body> <div style="height: 1000px"> <div id="back"> 返回页面顶部 </div> </div> </body> </html>
去除#back中position: fixed;(固定定位) bottom: 20px; right: 20px;效果为![]()
本文介绍了一个使用CSS实现的固定定位按钮示例。该按钮始终显示在屏幕底部右侧20像素的位置,即使滚动页面内容也能保持不变。通过设置position:fixed;、bottom:20px;及right:20px;属性实现这一效果。
359

被折叠的 条评论
为什么被折叠?



