一个浮动置顶的设计

本文探讨了如何使用HTML和CSS实现页面元素浮动置顶的效果。通过设置适当的class和CSS属性,可以确保内容在滚动时始终保持在屏幕的可见区域。这种设计适用于导航栏、侧边栏等需要始终可见的元素。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"  xml:lang="zh-CN" lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<meta http-equiv="Content-Language" content="zh-cn" />
<title>置顶测试</title>
<style type="text/css" media="screen">
<!--
* {margin:0;padding:0;}
body {margin:0 auto;font:12px/20px tahoma Simsun Arial;color:#fff;background-color:#FFF;text-align:center;}
.left-top{ width:150px; background:Blue;position:absolute;left:0;top:0; }
.right-top{ width:150px; background:Blue;position:absolute;right:0;top:0; }
.left-bottom{ width:150px; position:absolute; top:100%;left:0; margin-top:-20px;  background:Blue;}
.righ-bottom{ width:150px; position:absolute; top:100%;right:0; margin-top:-20px;  background:Blue;}
.float-left{ width:100%; position:fixed; background:Black; _position:absolute;_top:expression(eval(document.documentElement.scrollTop));z-index:1000;left:0;top:0; }
.float-right{ width:50px; position:fixed; background:Black; _position:absolute;_top:expression(eval(document.documentElement.scrollTop));z-index:1000;right:0;top:0; }
.a{ color:#000; }
  -->
</style>
</head>
<body>
<div class="float-left"><a href="#">测试</a></div>
<div class="a">
<br />
<br />
<br />
<br />
<br />
A层和B层会随滚动条移动永久置顶
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
</div>
</body>
</html>


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值