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


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

这个scroll-margin-inline-start属性用于一次将所有滚动边距设置为滚动元素的内联尺寸的开始。开始侧的选择取决于书写模式。开始侧是左侧horizontal-tb书写模式和顶部或底部verticle-lrverticle-rl分别写模式。
horizontal-tb代表horizontal top-to -bottomverticle-rl是个verticle right-to-leftverticle-lr是个verticle left-to-right

用法:

 scroll-margin-inline-start:length

或者

 scroll-margin-inline-start:Global_Values

属性值:scroll-margin-inline-start 属性接受上面提到和下面描述的两个属性。

  • length:该属性是指用长度单位定义的值,如 “em”、“px”、“rem”、“vh” 等。
  • Global_Values:此属性引用全局值,例如Inherit,Initial,unset等。

注意:这个scroll-margin-inline-start不接受百分比值作为长度。



例:在这个例子中,你可以看到效果scroll-margin-inline-start通过滚动到示例内容的两个接口之间的中间点。

HTML


<!DOCTYPE html>
<html>
  
<head>
    <style>
        .scroll {
            width:300px;
            height:300px;
            overflow-x:scroll;
            display:flex;
            box-sizing:border-box;
            scroll-snap-type:x mandatory;
        }
  
        .scroll>div {
            flex:0 0 300px;
            border:1px solid #000;
            background-color:#57e714;
            color:#fff;
            font-size:40px;
            display:flex;
            align-items:center;
            justify-content:center;
            scroll-snap-align:start;
        }
  
        .scroll>div:nth-child(2n) {
            background-color:#fff;
            color:#0fe962;
        }
  
        .scroll>div:nth-child(2) {
            scroll-margin-inline-start:2rem;
        }
  
        .scroll>div:nth-child(3) {
            scroll-margin-inline-start:3rem;
        }
    </style>
</head>
  
<body>
    <div class="scroll">
        <div>Geek 1</div>
        <div>Geek 2</div>
        <div>Geek 3</div>
        <div>Geek 4</div>
    </div>
</body>
  
</html>

输出:

支持的浏览器:

  • Firefox
  • Chrome
  • Edge
  • Opera

注意:不支持 Internet Explorer 和 Safari。




相关用法


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