display - SVG 编辑

The display attribute lets you control the rendering of graphical or container elements.

display属性让你可以控制图形元素或容器元素的渲染。

A value of display="none" indicates that the given element and its children will not be rendered. Any value other than none or inherit indicates that the given element will be rendered by the browser.

display="none"表示该元素和它的子元素不会被渲染。而非noneinherit的值表示元素会被浏览器渲染。

When applied to a container element, setting display to none causes the container and all of its children to be invisible; thus, it acts on groups of elements as a group. This means that any child of an element with display="none" will never be rendered even if the child has a value for display other than none.

当应用到容器元素时,将display设为none会导致容器与它所有的子元素不可见,如此看来,它在一组元素中表现地像一个元素组。这表示具有display="none"属性元素的所有子元素都不会被渲染,即使子元素的display并不是none

When the display attribute is set to none, then the given element does not become part of the rendering tree. It has implications for the <tspan>, <tref>, and <altGlyph> elements, event processing, for bounding box calculations and for calculation of clipping paths:

display属性被设为none的元素不会成为渲染树的一部分。它涉及到<tspan>, <tref>, 和 <altGlyph>元素、用于盒边界与路径剪裁计算的事件处理。

  • If display is set to none on a <tspan>, <tref>, or <altGlyph> element, then the text string is ignored for the purposes of text layout.

         如果在<tspan>, <tref>, 或<altGlyph>元素中display的属性值被设为none,则为了文字布局,文字字符串会被忽视掉。

  • Regarding events, if display is set to none, the element receives no events.

         至于事件,如果display被设为none则该元素不接受任何事件。

  • The geometry of a graphics element with display set to none is not included in bounding box and clipping paths calculations.

         图形元素的display属性被设为none则不会被盒边界和路径剪裁计算中包含进去。

The display attribute only affects the direct rendering of a given element, whereas it does not prevent elements from being referenced by other elements. For example, setting it to none on a <path> element will prevent that element from getting rendered directly onto the canvas, but the <path> element can still be referenced by a <textPath> element; furthermore, its geometry will be used in text-on-a-path processing even if the <path> has a display value of none.

display属性只影响能被直接渲染的元素,尽管它不能防止该元素被其他元素参考。例如:将{SVGElement("path")}}元素设为none,会使得该元素不会被直接渲染到canvas上,但是<textPath>元素依旧会参考<path>。此外,即便{SVGElement("path")}}的displaynone,它的形状在处理路径上的文本时仍然会被用到。

This attribute also affects direct rendering into offscreen canvases, such as occurs with masks or clip paths. Thus, setting display="none" on a child of a <mask> will prevent the given child element from being rendered as part of the mask. Similarly, setting display="none" on a child of a <clipPath> element will prevent the given child element from contributing to the clipping path.

这个属性也能影响直接渲染到屏幕外的画布,比如遮罩或路径剪裁。因此,把<mask>元素的一个子元素设为display="none"将会阻止子元素参与到路径剪裁中。

Note: As a presentation attribute, display can be used as a CSS property. See css display for further information.

As a presentation attribute, it can be applied to any element.

html, body, svg {
  height: 100%;
}
<svg viewBox="0 0 220 100" xmlns="http://www.w3.org/2000/svg">
  <!-- Here the yellow rectangle is displayed -->
  <rect x="0" y="0" width="100" height="100" fill="skyblue"></rect>
  <rect x="20" y="20" width="60" height="60" fill="yellow"></rect>

  <!-- Here the yellow rectangle is not displayed -->
  <rect x="120" y="0" width="100" height="100" fill="skyblue"></rect>
  <rect x="140" y="20" width="60" height="60" fill="yellow" display="none"></rect>
</svg>

Usage notes

Default valueinline
Value[ <display-outside> || <display-inside> ] | <display-listitem> | <display-internal> | <display-box> | <display-legacy>

where
<display-outside> = block | inline | run-in
<display-inside> = flow | flow-root | table | flex | grid | ruby
<display-listitem> = <display-outside>? && [ flow | flow-root ]? && list-item
<display-internal> = table-row-group | table-header-group | table-footer-group | table-row | table-cell | table-column-group | table-column | table-caption | ruby-base | ruby-text | ruby-base-container | ruby-text-container
<display-box> = contents | none
<display-legacy> = inline-block | inline-list-item | inline-table | inline-flex | inline-grid

AnimatableYes

For a description of the values, please refer to the css display property.

Specifications

SpecificationStatusComment
Scalable Vector Graphics (SVG) 2
display
Candidate RecommendationRefers to the CSS 2 specification of the display property, but outlines the differences regarding SVG.
Scalable Vector Graphics (SVG) 1.1 (Second Edition)
display
RecommendationInitial definition

Browser compatibility

BCD tables only load in the browser

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.

See also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:49 次

字数:16266

最后编辑:7年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文