บทนำ
SVG (Scalable Vector Graphics) ใช้สำหรับวาดกราฟิกเวกเตอร์ 2 มิติใน HTML5 สามารถวาดรูปทรงพื้นฐานได้ง่ายๆ
รูปทรงหลักใน SVG
| แท็ก | คำอธิบาย | แอตทริบิวต์หลัก |
|---|---|---|
<rect> | สี่เหลี่ยมผืนผ้า | x, y, width, height, rx, ry |
<circle> | วงกลม | cx, cy, r |
<ellipse> | วงรี | cx, cy, rx, ry |
<line> | เส้นตรง | x1, y1, x2, y2 |
<polyline> | เส้นโป๊ล리라น | points |
<polygon> | รูปหลายเหลี่ยม | points |
<path> | เส้นทางซับซ้อน | d (path data) |
ตัวอย่างสี่เหลี่ยมผืนผ้า
<!DOCTYPE html>
<html>
<head>
<style>
#svgelem { position: relative; left: 10%; transform: translateX(-20%); }
</style>
<title>SVG Rectangle</title>
</head>
<body>
<h2>HTML5 SVG Rectangle</h2>
<svg id="svgelem" width="300" height="200" xmlns="https://www.w3.org/2000/svg">
<rect width="200" height="100" fill="green" />
</svg>
</body>
</html>