當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。