官术网_书友最值得收藏!

  • D3.js Quick Start Guide
  • Matthew Huntington
  • 195字
  • 2021-07-16 17:36:41

Positioning an element

The <svg> tag is an inline element, such as an image (as opposed to a block element such as a <div>).  Elements within the <svg> are positioned similar to Photoshop, with a set of coordinates that follow the form (x,y).  An example of this could be (10,15), which translates to x=10 and y=15. This is different than HTML, where elements are laid out relative to one another. Here are some important things to keep in mind:

  • The point (0,0) is the upper–left corner of the <svg> element.
  • As y values increase, the point moves vertically down the <svg> element.
  • Don't confuse this with a typical coordinate system that has (0,0) at the lower–left corner with a point moving up, as y increases in value. This diagram shows the difference between a traditional coordinate system and an SVG coordinate system:

We can use negative x/y values:

  • -x: moves left
  • -y :moves up

Let's adjust the position of our circle in our previous section by adjusting cx and cy values (the x and y values for the center of the element):

<!DOCTYPE html>
<html lang="en" dir="ltr">
    <head>
    </head>
    <body>
        <svg>
            <circle r=50 cx=50 cy=50></circle>
        </svg>
    </body>
</html>

Now we see the full circle:

主站蜘蛛池模板: 定兴县| 华安县| 长治县| 平山县| 开鲁县| 霸州市| 山丹县| 中牟县| 盐山县| 宜州市| 瑞昌市| 东光县| 六枝特区| 富蕴县| 鲁甸县| 手游| 富顺县| 军事| 寿光市| 塔城市| 睢宁县| 利川市| 安义县| 烟台市| 深圳市| 屯门区| 黎城县| 靖边县| 台东市| 黔东| 唐山市| 彝良县| 义马市| 广饶县| 镇江市| 长海县| 侯马市| 汨罗市| 连云港市| 苗栗市| 大竹县|