scroll-margin-block-start 屬性用於一次將所有滾動邊距設置為滾動元素的開始側。這個性質定義塊尺寸開始處的滾動捕捉區域的邊距,用於將此框捕捉到捕捉端口。
用法:
scroll-margin-block-start:length /* Or */ scroll-margin-block-start:Global_Values
屬性值:此屬性接受上麵提到和下麵描述的兩個屬性:
- length:此屬性引用以長度單位(例如em,px,rem,vh等)定義的值。
- Global_Values:此屬性引用全局值,例如Inherit,Initial,unset等。
注:scroll-margin-block-開始不接受百分比值作為長度。
例:在此示例中,您可以通過滾動到示例內容的兩個 “interfaces” 之間的中間點來查看 scroll-margin-block-start 的效果。
HTML
<!DOCTYPE html>
<html>
<head>
<style>
.interfaces {
width:280px;
height:300px;
scroll-snap-align:start none;
box-sizing:border-box;
display:flex;
align-items:center;
justify-content:center;
font-size:60px;
color:white;
}
.Container {
width:300px;
height:300px;
overflow-x:hidden;
overflow-y:auto;
white-space:nowrap;
scroll-snap-type:y mandatory;
}
</style>
</head>
<body>
<div class="Container">
<div class="interfaces" style=
"background-color:rgb(117, 228, 27);
scroll-margin-block-start:80px;">
Geeks 1
</div>
<div class="interfaces" style=
"background-color:green;
scroll-margin-block-start:50px;">
for 2
</div>
<div class="interfaces" style=
"color:black;
scroll-margin-block-start:100px;">
Geeks 3
</div>
<div class="interfaces"
style="background-color:rgb(60, 184, 126);
scroll-margin-block-start:80px;">
for 4
</div>
<div class="interfaces" style=
"background-color:rgb(30, 253, 30);
scroll-margin-block-start:80px;">
Geeks 5
</div>
</div>
</body>
</html>
輸出:
支持的瀏覽器:
- Firefox
- Chrome
- Opera
- Edge
相關用法
- CSS transition-property用法及代碼示例
- CSS table-layout用法及代碼示例
- CSS text-align用法及代碼示例
- CSS border-top-width用法及代碼示例
- CSS isolation屬性用法及代碼示例
- CSS border-inline-start-style屬性用法及代碼示例
- CSS column-rule-width用法及代碼示例
- CSS word-spacing用法及代碼示例
- CSS animation-delay用法及代碼示例
- CSS margin-top用法及代碼示例
- CSS grid屬性用法及代碼示例
- CSS font-size-adjust用法及代碼示例
- CSS visibility屬性用法及代碼示例
- CSS Display屬性用法及代碼示例
- CSS grid-template-columns用法及代碼示例
- CSS height屬性用法及代碼示例
- CSS transform-origin用法及代碼示例
- CSS animation-name用法及代碼示例
- CSS flex-wrap用法及代碼示例
注:本文由純淨天空篩選整理自thacker_shahid大神的英文原創作品 CSS scroll-margin-block-start property。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。