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.
编者草案

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
margin-trim Experimental Chrome 不支持 No Edge 不支持 No Firefox 不支持 No 注意事项
不支持 No 注意事项
注意事项 bug 1506241 .
IE 不支持 No Opera 不支持 No Safari 不支持 No WebView Android 不支持 No Chrome Android 不支持 No Firefox Android 不支持 No 注意事项
不支持 No 注意事项
注意事项 bug 1506241 .
Opera Android 不支持 No Safari iOS 不支持 No Samsung Internet Android 不支持 No

图例

不支持

不支持

实验。期望将来行为有所改变。

实验。期望将来行为有所改变。

见实现注意事项。

见实现注意事项。

另请参阅

元数据

  • 最后修改: