【问题标题】:SVG how to set max width for groupSVG如何设置组的最大宽度
【发布时间】:2019-10-05 13:58:57
【问题描述】:

我有一些 SVG 元素组合在一个 <g> 元素中(正是一维条码,PHP 生成一个条码)。

  <g
 style="fill:#000000;stroke:none"
 id="barcode1D"
 transform="matrix(1.2083333,0,0,0.8247805,62.027778,573.54235)">
<rect
   x="0"
   y="0"
   width="4"
   height="30"
   id="xyz" />

....

    <rect
   x="224"
   y="0"
   width="0"
   height="30"
   id="xyzn" /> </g>

条形码以各种宽度、长度生成。如何永久设置宽度?

基于这个例子,我请求一个提示。提前感谢您的帮助。

【问题讨论】:

    标签: svg barcode


    【解决方案1】:

    SVG g element does not have width and height attributes。因此,您不能为其设置heightwidth

    您应该使用foreignObjectsvg 来执行此操作。

    <svg width="640" height="480" xmlns="http://www.w3.org/2000/svg">
      <foreignObject id="G" width="300" height="200">
        <svg>
         <!-- Barcode here -->
         <rect fill="black" stroke-width="2" height="112" width="84" y="55" x="55" stroke="#000000"/>
         <circle fill="#FF0000" stroke="#000000" stroke-width="5"  cx="155" cy="65" id="svg_7" r="50"/>     
        </svg>
      </foreignObject>
    </svg>

    【讨论】:

    • foreignObject 的意义何在? 元素具有宽度和高度。
    • 没错。我需要一个始终以相同宽度缩放生成的条形码的解决方案(容器)。
    • 很遗憾,没有;/
    • @PiccoloTest 你应该添加更多信息。
    • PHP 生成条形码 - 随机宽度。我需要 SVG 将嵌入的条形码转换为恒定的宽度。可能吗 ?从SVG级别
    猜你喜欢
    • 2018-11-11
    • 2014-06-26
    • 2016-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-10
    • 2017-12-26
    相关资源
    最近更新 更多