<foreignObject>

<foreignObject> SVG 元素包含來自不同 XML 名稱空間的元素。在瀏覽器的上下文中,它最可能是 (X)HTML。

示例

html
<svg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg">
  <style>
    div {
      color: white;
      font: 18px serif;
      height: 100%;
      overflow: auto;
    }
  </style>

  <polygon points="5,5 195,10 185,185 10,195" />

  <!-- Common use case: embed HTML text into SVG -->
  <foreignObject x="20" y="20" width="160" height="160">
    <!--
      In the context of SVG embedded in an HTML document, the XHTML
      namespace could be omitted, but it is mandatory in the
      context of an SVG document
    -->
    <div xmlns="http://www.w3.org/1999/xhtml">
      Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed mollis mollis
      mi ut ultricies. Nullam magna ipsum, porta vel dui convallis, rutrum
      imperdiet eros. Aliquam erat volutpat.
    </div>
  </foreignObject>
</svg>

屬性

height

foreignObject 的高度。值型別<length>|<percentage>預設值auto可動畫

width

foreignObject 的寬度。值型別<length>|<percentage>預設值auto可動畫

x

foreignObject 的 x 座標。值型別<length>|<percentage>預設值0可動畫

y

foreignObject 的 y 座標。值型別<length>|<percentage>預設值0可動畫

注意:從 SVG2 開始,xywidthheight幾何屬性,這意味著這些屬性也可以用作該元素的 CSS 屬性。

使用上下文

類別
允許的內容任何元素或字元資料

規範

規範
可縮放向量圖形 (SVG) 2
# ForeignObjectElement

瀏覽器相容性

BCD 表格僅在啟用 JavaScript 的瀏覽器中載入。