元素的逻辑块结束边距由 margin-block-end CSS 属性指定,该属性根据元素的写入模式、方向性和文本方向转换为物理边距。
- 根据 write-mode、direction 和 text-orientation 给出的值,它对应于 margin-left、margin-top、margin-right 或 margin-bottom 属性。
- 它与元素 margin-block-start、margin-inline-start 和 margin-inline-end 相关,它们指定元素的剩余边距。
可能的值
以下列表涵盖了 margin-block-end 属性的所有可能值,这些值类似于 margin-left 属性。
- <length> - 边距大小的固定值。
- <percentage> - 相对于包含块的内联大小或水平语言中写入模式定义的宽度所测量的边距的百分比。
- auto - 将一定百分比的可用水平空间分配给左边距,所选的布局选项起着至关重要的作用。当 margin-left 和 margin-right 值都设置为 auto 时,margin-left 和 margin-right 值之间的间距相等。
适用于
所有元素(具有表格的元素除外)显示类型不是 table-caption、table 和 inline-table。它也适用于 ::first-letter。
语法
margin-block-end = <'margin-top'>
CSS margin-block-end - 长度值
以下示例演示了 margin-block-end 与长度值的用法。
<html>
<head>
<style>
body {
background-color: #F1ECEC;
}
#customDIV {
height: 400px;
background-color: #FFF7B0;
padding: 20px;
}
.marginDemo {
width: 250px;
background-color: #8B78B6;
border: 2px dashed #4682B4;
margin-block-end: 25px;
}
.marginBox {
width: 250px;
background-color: #F3994D;
text-align: center;
padding: 10px;
}
</style>
</head>
<body>
<h1>Explore the margin-block-end property</h1>
<div id="customDIV">
<p>Orange div elements emphasize margins around the purple box.</p>
<div class="marginBox">box</div>
<div class="marginDemo">
Example of margin-block-end property.
</div>
<div class="marginBox">box</div>
</div>
</body>
</html>
CSS margin-block-end - 百分比值
以下示例演示了 margin-block-end 与百分比值的用法。
<html>
<head>
<style>
body {
background-color: #dfe4ed;
}
#customDIV {
height: 400px;
background-color: #edecb7;
padding: 20px;
}
.marginDemo {
width: 250px;
background-color: #65f252;
border: 2px dashed #4682B4;
margin-block-end: 20%;
}
.marginBox {
width: 250px;
background-color: #f5d902;
text-align: center;
padding: 10px;
}
</style>
</head>
<body>
<h1>Explore the margin-block-end property</h1>
<div id="customDIV">
<p>Yellow div elements emphasize margins around the green box.</p>
<div class="marginBox">box</div>
<div class="marginDemo">
Example of margin-block-end property.
</div>
<div class="marginBox">box</div>
</div>
</body>
</html>
CSS margin-block-end - 自动值
以下示例演示了 margin-block-end 与 auto value 的用法。
<html>
<head>
<style>
body {
background-color: #F2EFEF;
}
#customDIV {
height: 400px;
background-color: #FFEEA8;
padding: 20px;
}
.marginDemo {
width: 250px;
background-color: #6495ED;
border: 4px dashed #4682B4;
margin-block-end: auto;
}
.marginBox {
width: 250px;
background-color: #FFA07A;
text-align: center;
padding: 10px;
}
</style>
</head>
<body>
<h1>Explore the margin-block-end property</h1>
<div id="customDIV">
<p>Orange div elements emphasize margins around the blue box.</p>
<div class="marginBox">box</div>
<div class="marginDemo">
Example of margin-block-end property.
</div>
<div class="marginBox">box</div>
</div>
</body>
</html>
CSS margin-block-end - 写入模式
以下示例演示了 margin-block-end 与长度值和写入模式的用法:vertical-rl。
<html>
<head>
<style>
body {
background-color: #E3EAE9;
}
#customDIV {
height: 500px;
background-color: #FFEACB;
padding: 20px;
}
.marginDemo {
width: 50px;
background-color: #87CEEB;
border: 4px dashed #2E517F;
margin-block-end: 20px;
writing-mode: vertical-rl;
}
.marginBox {
width: 150px;
background-color: #FF9A8B;
text-align: center;
padding: 10px;
}
</style>
</head>
<body>
<h1>Explore the margin-block-end property</h1>
<div id="customDIV">
<p>Orange div elements emphasize margins around the blue box.</p>
<div class="marginBox">box</div>
<div class="marginDemo">
Example of margin-block-end property
</div>
<div class="marginBox">box</div>
</div>
</body>
</html>