SVG - 直線



<line> 元素用於繪製具有起點和終點的直線。

宣告

以下是 <line> 元素的語法宣告。我們只展示了主要屬性。

<line
   x1="x-axis co-ordinate"
   y1="y-axis co-ordinate"
   
   x2="x-axis co-ordinate" 
   y2="y-axis co-ordinate" >    
</line>

屬性

序號 名稱及描述
1 x1 − 起點的 x 軸座標。預設為 0。
2 y1 − 起點的 y 軸座標。預設為 0。
3 x2 − 終點的 x 軸座標。預設為 0。
4 y2 − 終點的 y 軸座標。預設為 0。

示例

testSVG.htm
<html>
   <title>SVG Line</title>
   <body>
      
      <h1>Sample SVG Line Image</h1>
      
      <svg width="800" height="800">
         <g>
            <text x="0" y="15" fill="black" >Line #1: Without opacity.</text>
            
            <line x1="20" y1="20" x2="150" y2="150" 
            stroke="black" stroke-width="3" fill="rgb(121,0,121)"></line> 
         </g> 
      </svg>
   
   </body>
</html>

輸出

在 Chrome 瀏覽器中開啟 textSVG.htm。您可以使用 Chrome/Firefox/Opera 直接檢視 SVG 影像,無需任何外掛。Internet Explorer 9 及更高版本也支援 SVG 影像渲染。

帶有透明度的直線

<html>
   <title>SVG Line</title>
   <body>
      
      <h1>Sam>le SVG Line Image</h1>
      
      <svg width="800" height="800"> 
         <g>
            <text x="0" y="15" fill="black" >Line #2: With opacity </text>
            
            <line x1="20" y1="20" x2="150" y2="150"  
            style="fill:rgb(121,0,121);stroke-width:3;
            stroke:rgb(0,0,0);stroke-opacity:0.5;opacity:0.5"></line> 
         </g>
      </svg>
   
   </body>
</html>

輸出

在 Chrome 瀏覽器中開啟 textSVG.htm。您可以使用 Chrome/Firefox/Opera 直接檢視 SVG 影像,無需任何外掛。Internet Explorer 9 及更高版本也支援 SVG 影像渲染。

svg_shapes.htm
廣告