2017-06-15 48 views
2

我已经显示在SVG格式的下列项目列表和优惠的价格。SVG文本 - 一个文本左对齐,并在同一行中其他文本必须右对齐

瓶........... $ 5.00
瓶的说明

台式机配件........... $ 25.00
的桌面附件说明

谁能帮我在svgList的右侧布局价如图所示image下面也显示。

瓶................................. $ 5.00
瓶的说明

桌面配件...........的桌面配件

的SVG代码为$ 25.00
说明如下:

<svg id=“svgList” width="816" height="400" class="myBGImage"> 
     <g id="main"> 

      <g id="subGroup01" class="group" transform="translate(20,100)" style="cursor: move; -webkit-tap-highlight-color: rgba(0, 0, 0, 0);"> 
       <text alignment-baseline="baseline" text-anchor="start" data-type="itemtitle" id="itemtitle_h0f0" class="roboto_global fontSize_20g" stroke-width="2" color="#000000"> 
       <tspan class="item" text-anchor="start" x="0" y="0">Bottles</tspan> 
       <tspan class="dots" text-anchor="start">...............</tspan> 
       <tspan class="price" text-anchor="start">$5.00</tspan> 
       <tspan class="item-desc" text-anchor="start" x="0" y="20">Description </tspan> 
       </text> 
      </g> 
      <g id="subGroup02" class="group" transform="translate(20,150)" style="cursor: move; -webkit-tap-highlight-color: rgba(0, 0, 0, 0);"> 
       <text alignment-baseline="baseline" text-anchor="start" data-type="itemtitle" id="itemtitle_h0f1" class="roboto_global fontSize_20g" stroke-width="2" color="#000000"> 
       <tspan class="item" text-anchor="start" x="0" y="0">Desktop accessories</tspan> 
       <tspan class="dots" text-anchor="start">...............</tspan> 
       <tspan class="price" text-anchor="start">$25.00</tspan> 
       <tspan class="item-desc" text-anchor="start" x="0" y="20">Description </tspan> 
       </text> 
      </g> 
     </g> 
</svg> 

链接fiddle

+0

你为什么使用SVG?文本布局实际上是HTML更适合的东西。 – ccprog

+0

我需要这个列表,因为这个列表必须被打印。而且SVG给出了很好的分辨率 – anuja

+0

这两个要求都可以通过html来满足。 –

回答

2

您正在使用text-anchor="start",你有没有尝试text-anchor="end"

这与定位问题的交易。唯一有点棘手的是如何做可变宽度点,而不必确切地计算出每种情况下需要使用多少个点。

我在我的解决方案所采用的方法(见下方例子)是使用虚线。

<svg id="svgList" width="816" height="400" class="myBGImage"> 
 
    <g transform="translate(20,100)"> 
 
    <line x1="0" y1="0" x2="250" y2="0" stroke="black" stroke="1" stroke-dasharray="2 2"/> 
 
    <text class="item" text-anchor="start" x="0" y="0">Bottles</text> 
 
    \t <text class="price" text-anchor="end" x="250">$5.00</text> 
 
    </g> 
 
</svg>

然后隐藏文本后面的点,我们添加原文后面的文本的额外副本。然后,我们将该文本的额外副本作为粗白笔划来隐藏虚线的相关部分。它具有文字周围的白色“光环”效果,可以消除文字背后的虚线部分。

在这个小片段,我所做的卒中/光环蓝色,表示发生了什么。

<svg id="svgList" width="816" height="400" class="myBGImage"> 
 
    <g transform="translate(20,100)"> 
 
    <line x1="0" y1="0" x2="250" y2="0" stroke="black" stroke="1" stroke-dasharray="2 2"/> 
 
    <use xlink:href="#row1" stroke="blue" stroke-width="6"/> 
 
    <g id="row1" fill="white"> 
 
     <text class="item" text-anchor="start" x="0" y="0">Bottles</text> 
 
     <text class="price" text-anchor="end" x="250">$5.00</text> 
 
    </g> 
 
    <text class="item-desc" text-anchor="start" x="0" y="20">Description </text> 
 
    </g> 
 
</svg>

最终结果:

<svg id="svgList" width="816" height="400" class="myBGImage"> 
 
    <g id="main"> 
 

 
    <g id="subGroup01" class="group" transform="translate(20,100)" style="cursor: move; -webkit-tap-highlight-color: rgba(0, 0, 0, 0);"> 
 
     <line x1="0" y1="0" x2="250" y2="0" stroke="black" stroke="1" stroke-dasharray="2 2"/> 
 
     <use xlink:href="#row1" stroke="white" stroke-width="4"/> 
 
     <g id="row1"> 
 
     <text class="item" text-anchor="start" x="0" y="0">Bottles</text> 
 
     <text class="price" text-anchor="end" x="250">$5.00</text> 
 
     </g> 
 
     <text class="item-desc" text-anchor="start" x="0" y="20">Description </text> 
 
    </g> 
 

 
    <g id="subGroup02" class="group" transform="translate(20,150)" style="cursor: move; -webkit-tap-highlight-color: rgba(0, 0, 0, 0);"> 
 
     <line x1="0" y1="0" x2="250" y2="0" stroke="black" stroke="1" stroke-dasharray="2 2"/> 
 
     <use xlink:href="#row2" stroke="white" stroke-width="4"/> 
 
     <g id="row2"> 
 
     <text class="item" text-anchor="start" x="0" y="0">Desktop accessories</text> 
 
     <text class="price" text-anchor="end" x="250">$25.00</text> 
 
     </g> 
 
     <text class="item-desc" text-anchor="start" x="0" y="20">Description </text> 
 
    </g> 
 

 
    </g> 
 
</svg>

+0

嗨@Paul LeBeau,感谢代码对虚线非常有帮助,对我来说,挑战在于我有一个附加到svgList的背景图像。如果它只是背景颜色,而不是通过给背景赋予与背景相同的颜色来处理。在处理背景图片时可以提出什么样的建议? [小提琴](https://jsfiddle.net/anujas/yrk5nsr6/2/) – anuja

+0

是的。而不是绘制白色(如上所述)以隐藏点,而是使用额外的文本元素来创建“”。 –

+0

将那个面具与给svglist的背景图像混合?如果是的话,我应该试试这个。 – anuja