当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


CSS scroll-margin-right属性用法及代码示例


scroll-margin-right属性用于一次将所有滚动边距设置到元素的右侧。为scroll-margin-right指定的值确定应该本质上保留在快照端口之外的页面数量。

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

用法:

scroll-margin-right:length
/* Or */
scroll-margin-right:Global_Value

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

  • length:此属性引用以长度单位exp:px,em,vh等定义的值。
  • Global_Values:此属性引用全局值,例如Inherit,Initial,unset等。

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



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

<!DOCTYPE html> 
<html> 
  
<head> 
    <style> 
        img { 
              width:300px; 
              height:280px; 
              scroll-snap-align:none end; 
        } 
        .Gallery { 
              width:300px; 
              height:300px; 
              overflow-x:auto; 
              overflow-y:hidden; 
              white-space:nowrap; 
              scroll-snap-type:x mandatory; 
        } 
    </style> 
</head> 
<body> 
    <div class="photoGallery"> 
  
          <img src= 
"https://media.geeksforgeeks.org/wp-content/uploads/20200723131450/img6-300x82.png" 
          style="scroll-margin-right:50px;"> 
  
          <img src= 
"https://media.geeksforgeeks.org/wp-content/uploads/20200723131449/img5.jpeg" 
          style="scroll-margin-right:60px;"> 
  
          <img src= 
"https://media.geeksforgeeks.org/wp-content/uploads/20200723131452/img4-300x167.png" 
          style="scroll-margin-right:-50px;"> 
  
    </div> 
</body> 
</html>

输出:

支持的浏览器:

  • Chrome
  • Firefox
  • Opera
  • Safari(部分支持)
  • Edge
  • Internet Explorer(不支持)

相关用法


注:本文由纯净天空筛选整理自thacker_shahid大神的英文原创作品 CSS scroll-margin-right property。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。