粘性定位

这是一个结合了 position:relative 和 position:fixed 两种定位功能于一体的特殊定位,适用于一些特殊场景。( 即元素先按照普通文档流定位,之后为固定定位。)

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>1111</title>
        <style>
			html {
			box-sizing: border-box;
			}
			html,
			body {
			overflow: hidden;
			}
			*, *:before, *:after {
			box-sizing: inherit;
			}
			body {
			background-color: #196e76;
			line-height: 1.2;
			}
			.cf:before,
			.cf:after {
				content: " "; /* 1 */
				display: table; /* 2 */
			}

			.cf:after {
				clear: both;
			}

			/**
			* For IE 6/7 only
			* Include this rule to trigger hasLayout and contain floats.
			*/
			.cf {
				*zoom: 1;
			}
			.scroll {
			height: 500px;
			overflow: scroll;
			background-color: #e7ebef;
			padding: 0 10px;
			width: 100%;
			max-width: 550px;
			margin-right: auto;
			margin-left: auto;
			margin-top: 20px;
			margin-bottom: 200px;
			}
			.wrapper {
			margin-top: 310px;
			}
			.content {
			padding: 0 15px;
			width: 330px;
			}
			.content h1 {
			margin-top: 0;
			}
			.content p,
			.sidebar p{
			font-family: "BLOKKNeue-Regular";
			}
			.sidebar {
			padding: 20px;
			width: 170px;
			background-color: #434A54;
			color: #fff;
			}
			.sidebar h3 {
			margin: 0;
			}
			.content,
			.sidebar {
			float: left;
			}


			/* The sticky */
			.sidebar {
			position: -webkit-sticky;
			position: sticky;
			top: 15px;
			}
		</style>
    </head>
    <body> 
		<div class="scroll">
			<div class="wrapper cf">
			  <div class="content">
				<h1>Scroll Down!</h1>
				<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est.
				  Mauris placerat eleifend leo.</p>
				<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Atque vero, maxime nulla dolore iure voluptatem itaque. Nisi commodi ut consectetur beatae mollitia. Ab, maxime quisquam ipsa, quibusdam itaque et eius.</p>
				<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Expedita, molestiae.</p>
				<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Minus suscipit blanditiis delectus quos, soluta fuga voluptatem, facere inventore neque voluptate quaerat unde laboriosam molestiae repellat, sapiente accusamus cumque! Ipsam, illo!</p>
				<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est.
					Mauris placerat eleifend leo.</p>
				  <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Atque vero, maxime nulla dolore iure voluptatem itaque. Nisi commodi ut consectetur beatae mollitia. Ab, maxime quisquam ipsa, quibusdam itaque et eius.</p>
				  <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Expedita, molestiae.</p>				
			  </div>			 
			</div>
		  </div>
        <script>
           
        </script>
    </body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值