These keywords define whether an element generates display boxes at all.

句法

Valid <display-box> values:

contents
These elements don't produce a specific box by themselves. They are replaced by their pseudo-box and their child boxes. Please note that the CSS Display Level 3 spec defines how the contents value should affect "unusual elements" — elements that aren’t rendered purely by CSS box concepts such as replaced elements. See Appendix B: Effects of display: contents on Unusual Elements 了解更多细节。

Due to a bug in browsers this will currently remove the element from the accessibility tree — screen readers will not look at what's inside. See the 可访问性关注 section below for more details.
none
Turns off the display of an element so that it has no effect on layout (the document is rendered as though the element did not exist). All descendant elements also have their display turned off.
To have an element take up the space that it would normally take, but without actually rendering anything, use the visibility 特性代替。

可访问性关注

Current implementations in most browsers will remove from the accessibility tree any element with a display value of contents . This will cause the element — and in some browser versions, its descendant elements — to no longer be announced by screen reading technology. This is incorrect behavior according to the CSSWG specification .

范例

In this first example, the paragraph with a class of secret is set to display: none ; the box and any content is now not rendered.

display: none

HTML

<p>Visible text</p>
<p class="secret">Invisible text</p>
					

CSS

p.secret {
  display: none;
}
					

结果

display: contents

In this example the outer <div> has a 2-pixel red border and a width of 300px. However it also has display: contents specified therefore this <div> will not be rendered, the border and width will no longer apply, and the child element will be displayed as if the parent had never existed.

HTML

<div class="outer">
  <div>Inner div.</div>
</div>
					

CSS

.outer {
  border: 2px solid red;
  width: 300px;
  display: contents;
}
.outer > div {
  border: 1px solid green;
}
					

结果

规范

规范 状态
CSS Display Module Level 3
The definition of 'display-box' 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.

Support of contents

更新 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
contents Chrome 完整支持 65
完整支持 65
不支持 58 — 65 Disabled
Disabled From version 58 until version 65 (exclusive): this feature is behind the Enable experimental Web Platform features preference. To change preferences in Chrome, visit chrome://flags.
Edge 完整支持 79 Firefox 完整支持 37
完整支持 37
不支持 36 — 53 Disabled
Disabled ). To change preferences in Firefox, visit
IE 不支持 No Opera 完整支持 52
完整支持 52
不支持 45 — 52 Disabled
Disabled From version 45 until version 52 (exclusive): this feature is behind the Enable experimental Web Platform features preference.
Safari 完整支持 11.1 WebView Android 完整支持 65 Chrome Android 完整支持 65
完整支持 65
不支持 58 — 65 Disabled
Disabled From version 58 until version 65 (exclusive): this feature is behind the Enable experimental Web Platform features preference. To change preferences in Chrome, visit chrome://flags.
Firefox Android 完整支持 57 Opera Android 完整支持 47
完整支持 47
不支持 43 — 47 Disabled
Disabled From version 43 until version 47 (exclusive): this feature is behind the Enable experimental Web Platform features preference.
Safari iOS 完整支持 11.3 Samsung Internet Android 完整支持 9.0
Specific behavior of unusual elements when display: contents is applied to them Chrome 完整支持 58 Edge 完整支持 79 Firefox 完整支持 59 IE 不支持 No Opera 完整支持 45 Safari 不支持 No WebView Android 完整支持 65 Chrome Android 完整支持 58 Firefox Android 完整支持 59 Opera Android 完整支持 43 Safari iOS 不支持 No Samsung Internet Android 完整支持 9.0

图例

完整支持

完整支持

不支持

不支持

用户必须明确启用此特征。

用户必须明确启用此特征。

另请参阅

元数据

  • 最后修改:
  1. CSS
  2. CSS 参考
  3. CSS Display
  4. 特性
    1. <display-box>
    2. <display-inside>
    3. <display-internal>
    4. <display-legacy>
    5. <display-listitem>
    6. <display-outside>
    7. display

Copyright  © 2014-2026 乐数软件    

工业和信息化部: 粤ICP备14079481号-1