From the course: Learning SVG
Unlock the full course today
Join today to access over 24,900 courses taught by industry experts.
Draw a rectangle - SVG Tutorial
From the course: Learning SVG
Draw a rectangle
- [Narrator] To create rectangles, we use the rect element. The rect element first defines the coordinates of the top left corner using the x and y attributes and then defines the width and height of the rectangle. These values are related to the current displayed SVGs. So in our example, we are working with a view box of 100 by 100, that means we need to make sure the combination of both the x value and the width, or the y value, and the height don't exceed 100 if we want the entire rectangle to display inside the view box. In exercise files for this movie, I've added in this example and here I've also added two classes this time, stroke and fill. So we get both the stroke around the rectangle and a fill inside it. Run this code in the browser and what you get is a rectangle that takes up some of the space. So here we start out at x line 20 and set a width of 40, so x 20 is here and I have a width of 40 units. Then for the height, we start at y 30, that's here, and then we set the…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
SVG shapes overview2m 31s
-
(Locked)
Draw a line2m 52s
-
(Locked)
Draw a rectangle4m 24s
-
(Locked)
Draw a circle1m 27s
-
(Locked)
Draw an ellipse1m 59s
-
(Locked)
Draw a polyline2m 44s
-
(Locked)
Draw a polygon2m 12s
-
(Locked)
Draw a path3m 59s
-
(Locked)
Add text to an SVG9m 4s
-
(Locked)
Convert text to outlines4m 42s
-
(Locked)
Add an external image to an SVG4m 4s
-
(Locked)
Rotate SVG shapes5m 18s
-
-
-
-