CSS scroll-margin-right 属性指定元素的滚动捕捉区域的右边距。
可能的值
- <length> - 长度值是一个数值,如px、em。
适用于
所有 HTML 元素。
DOM 语法
object.style.scrollMarginRight = "length";
CSS 滚动边距右 - 零值
以下示例演示如何使用 scroll-margin-right: 0,这会导致在各节的右侧未设置边距 -
<html>
<head>
<style>
.scroll-container {
display: flex;
width: 300px;
height: 200px;
overflow-x: scroll;
overflow-y: hidden;
scroll-snap-type: x mandatory;
}
.scrolling-section1,
.scrolling-section2,
.scrolling-section3 {
flex: 0 0 auto;
width: 300px;
height: 200px;
scroll-snap-align: end;
}
.scrolling-section1 {
background-color: rgb(220, 235, 153);
scroll-margin-right: 0;
}
.scrolling-section2 {
background-color: rgb(230, 173, 218);
scroll-margin-right: 0;
}
.scrolling-section3 {
background-color: rgb(119, 224, 210);
scroll-margin-right: 0;
}
</style>
</head>
<body>
<h3>Scroll the content using the scrollbar arrows to see the effect.</h3>
<div class="scroll-container">
<div class="scrolling-section1">scroll-margin-right: 0</div>
<div class="scrolling-section2">scroll-margin-right: 0</div>
<div class="scrolling-section3">scroll-margin-right: 0</div>
</div>
</body>
</html>
CSS Scroll Margin Right - 长度值
以下示例演示如何使用 scroll-margin-right 属性为每个部分添加右边距 -
<html>
<head>
<style>
.scroll-container {
display: flex;
width: 300px;
height: 200px;
overflow-x: scroll;
overflow-y: hidden;
scroll-snap-type: x mandatory;
}
.scrolling-section1,
.scrolling-section2,
.scrolling-section3 {
flex: 0 0 auto;
width: 300px;
height: 200px;
scroll-snap-align: end;
}
.scrolling-section1 {
background-color: rgb(220, 235, 153);
scroll-margin-right: 20px;
}
.scrolling-section2 {
background-color: rgb(230, 173, 218);
scroll-margin-right: 2em;
}
.scrolling-section3 {
background-color: rgb(119, 224, 210);
scroll-margin-right: 10px;
}
</style>
</head>
<body>
<h3>Scroll the content using the scrollbar arrows to see the effect.</h3>
<div class="scroll-container">
<div class="scrolling-section1">scroll-margin-right: 20px</div>
<div class="scrolling-section2">scroll-margin-right: 2em</div>
<div class="scrolling-section3">scroll-margin-right: 10px</div>
</div>
</body>
</html>