margin-trim
property allows the container to trim the margins of its children where they adjoin the container’s edges.
none
Margins are not trimmed by the container.
in-flow
For in-flow boxes contained by this box, block-axis margins adjacent to the box's edges are truncated to zero.
It also truncates any margins collapsed with such a margin.
all
Trims the margins of in-flow boxes and floats whose margins coincide with the container's content edge.
| 初始值 |
none
|
|---|---|
| 适用于 |
Block containers and multi-column containers. It also applies to
::first-letter
and
::first-line
.
|
| 继承 | no |
| 计算值 | 如指定 |
| 动画类型 | discrete |
none | in-flow | all
Once support is implemented for this property, it will probably work like so:
When you've got a container with some inline children and you want to put a margin between each child but not have it interfere with the spacing at the end of the row, you might do something like this:
article {
background-color: red;
margin: 20px;
padding: 20px;
display: inline-block;
}
article > span {
background-color: black;
color: white;
text-align: center;
padding: 10px;
margin-right: 20px;
}
The problem here is that you'd end up with 20px too much spacing at the right of the row, so you'd maybe do this to fix it:
span:last-child {
margin-right: 0;
}
It is a pain having to write another rule to achieve this, and it is also not very flexible. Instead,
margin-trim
could fix it:
article {
margin-trim: in-flow;
...
}
| 规范 | 状态 |
|---|---|
|
CSS Box Model Module Level 4
The definition of 'margin-trim' in that specification. |
编者草案 |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
margin-trim
Experimental
|
Chrome 不支持 No | Edge 不支持 No |
Firefox
不支持
No
注意事项
|
IE 不支持 No | Opera 不支持 No | Safari 不支持 No | WebView Android 不支持 No | Chrome Android 不支持 No |
Firefox Android
不支持
No
注意事项
|
Opera Android 不支持 No | Safari iOS 不支持 No | Samsung Internet Android 不支持 No |
不支持
实验。期望将来行为有所改变。
见实现注意事项。
height
margin-bottom
margin-left
margin-right
margin-top
margin-trim
max-height
max-width
min-height
min-width
overscroll-behavior
overscroll-behavior-block
overscroll-behavior-inline
overscroll-behavior-x
overscroll-behavior-y
padding
padding-bottom
padding-left
padding-right
padding-top
visibility
width