使用svg画一个三角形

<svg width="100" height="100">
  <polygon points="50,10 10,90 90,90" style="fill:blue; stroke:black; stroke-width:2" />
</svg>

This code creates an SVG image of a blue triangle with a black outline. Here's a breakdown:

  • <svg> tag: This defines the SVG canvas. width and height set the dimensions.
  • <polygon> tag: This draws the triangle.
  • points attribute: This specifies the vertices of the triangle. Each pair of numbers represents an x and y coordinate. 50,10 is the top vertex, 10,90 is the bottom-left, and 90,90 is the bottom-right. These coordinates are relative to the top-left corner of the SVG canvas.
  • style attribute: This sets the visual properties of the triangle:
    • fill:blue; sets the fill color to blue.
    • stroke:black; sets the outline color to black.
    • stroke-width:2; sets the outline thickness to 2 pixels.

You can embed this code directly into an HTML file to display the triangle. You can also adjust the points, fill, stroke, and stroke-width attributes to customize the triangle's appearance. For example, to create a red triangle filled with yellow:

<svg width="100" height="100">
  <polygon points="50,10 10,90 90,90" style="fill:yellow; stroke:red; stroke-width:3" />
</svg>
posted @ 2024-12-13 09:30  王铁柱6  阅读(95)  评论(0)    收藏  举报