元素的逻辑内联开始边距由 CSS 属性 margin-inline-start 指定。元素的书写模式、方向性和文本方向都会影响实际的物理边距。
- 此边距根据元素的书写模式、方向和文本方向而变化;它可以是 margin-left、margin-top、margin-right 或 margin-bottom 属性。
- 它与元素的其他边距相关,这些边距由 margin-block-start、margin-block-end 和 margin-inline-end 定义。
可能的值
以下列表涵盖了 margin-inline-start 属性的所有可能值,这些值类似于 margin-left 属性。
- <length> - 边距大小的固定值。
- <percentage> - 相对于包含块的内联大小或水平语言中写入模式定义的宽度所测量的边距的百分比。
- auto - 将一定百分比的可用水平空间分配给左边距,所选的布局选项起着至关重要的作用。当 margin-left 和 margin-right 值都设置为 auto 时,margin-left 和 margin-right 值之间的间距相等。
适用于
所有元素(具有表格的元素除外)显示类型不是 table-caption、table 和 inline-table。它也适用于 ::first-letter。
语法
margin-inline-start = <'margin-top'>
CSS margin-inline-start - 长度值
以下示例演示了 margin-inline-start 与长度值的用法。
<html>
<head>
<style>
body {
background-color: #F1F1F1;
}
#Container {
height: 280px;
background-color: #f5f1b8;
}
#Container > div {
width: 150px;
height: 200px;
float: left;
box-sizing: border-box;
}
.marginDemo {
background-color: #e67f09;
border: solid 3px #46262A;
text-align: center;
font-size: 20px;
margin-inline-start: 25px;
}
.marginBox {
background-color: #d7e609;
border: solid 2px #46262A;
text-align: center;
font-size: 20px;
padding: 10px;
}
</style>
</head>
<body>
<h1>Explore the margin-inline-start property.</h1>
<div id="Container">
<div class="marginBox">Box A</div>
<div class="marginDemo">
Example of css margin-inline-start property.
</div>
<div class="marginBox">Box B</div>
</div>
</body>
</html>
CSS margin-inline-start - 百分比值
以下示例演示了 margin-inline-start 与百分比值的用法。
<html>
<head>
<style>
body {
background-color: #F1F1F1;
}
#Container {
height: 280px;
background-color: #dcdce0;
}
#Container > div {
width: 150px;
height: 200px;
float: left;
box-sizing: border-box;
}
.marginDemo {
background-color: #87b9e8;
border: solid 3px #46262A;
text-align: center;
font-size: 20px;
margin-inline-start: 15%;
}
.marginBox {
background-color: #1272cc;
border: solid 3px #46262A;
text-align: center;
font-size: 20px;
padding: 10px;
}
</style>
</head>
<body>
<h1>Explore the margin-inline-start property.</h1>
<div id="Container">
<div class="marginBox">Alpha</div>
<div class="marginDemo">
Example of css margin-inline-start property.
</div>
<div class="marginBox">Beta</div>
</div>
</body>
</html>
CSS margin-inline-start - 自动和写入模式
以下示例演示了 margin-inline-start 与 auto value 和 writing-mode: vertical-rl 的用法。
<html>
<head>
<style>
body {
background-color: #F1F1F1;
}
#Container {
height: 280px;
background-color: #dcdce0;
}
#Container > div {
width: 150px;
height: 200px;
float: left;
box-sizing: border-box;
}
.marginDemo {
background-color: #d6625e;
border: solid 3px #46262A;
text-align: center;
font-size: 20px;
margin-inline-start: auto;
writing-mode: vertical-rl;
}
.marginBox {
background-color: #cc110a;
border: solid 3px #46262A;
text-align: center;
font-size: 20px;
padding: 10px;
}
</style>
</head>
<body>
<h1>Explore the margin-inline-start property.</h1>
<div id="Container">
<div class="marginBox">Alpha box</div>
<div class="marginDemo">
Example of css margin-inline-start property.
</div>
<div class="marginBox">Beta box</div>
</div>
</body>
</html>

