css中scroll怎么用,CSS scroll-margin-bottom属性用法及代码示例

scroll-margin-bottom属性用于将所有滚动边距一次性设置到元素的底部。为scroll-margin-bottom指定的值确定应该主要显示在支持范围之外的页面的多少。

因此,scroll-margin-bottom值代表定义了滚动捕捉区域的起始位置,该区域用于将该框捕捉到捕捉端口。

用法:

scroll-margin-bottom:length

/* Or */

scroll-margin-bottom:Global_Values

属性值:该属性接受上面提到并在下面描述的two-properties:

length:此属性引用以长度单位定义的值:px,rem,em,vh等。

Global_Values:此属性引用全局值,例如初始,继承,未设置等。

注意:scroll-margin-bottom不接受百分比值作为长度。

例:在此示例中,通过滚动到示例内容的“interfaces”中的两个之间的一个点,可以看到scroll-margin-bottom的效果。

HTML

.scroller {

width:300px;

height:300px;

overflow-x:hidden;

overflow-y:auto;

scroll-snap-type:y mandatory;

}

.scroller > div {

width:300px;

height:300px;

font-size:50px;

color:white;

display:flex;

align-items:center;

justify-content:center;

scroll-snap-align:end none;

}

.scroller div:nth-child(odd){

background-color:green;

scroll-margin-bottom:1rem;

}

.scroller div:nth-child(even){

background-color:rgb(160, 231, 45);

scroll-margin-bottom:3rem;

}

Geeks
for
Geeks
for
Geeks

输出:

7a2276b7dd59d48417cca1524f5be22a.gif

支持的浏览器:

Chrome

Firefox

Edge

Opera

Safari(partially supported)

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值