- 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:
推薦閱讀
- Hands-On Graph Analytics with Neo4j
- Design for the Future
- Learning Microsoft Azure Storage
- 深度學(xué)習(xí)中的圖像分類與對(duì)抗技術(shù)
- Supervised Machine Learning with Python
- OpenStack Cloud Computing Cookbook(Second Edition)
- 大型數(shù)據(jù)庫(kù)管理系統(tǒng)技術(shù)、應(yīng)用與實(shí)例分析:SQL Server 2005
- 大學(xué)計(jì)算機(jī)應(yīng)用基礎(chǔ)
- 西門子S7-200 SMART PLC實(shí)例指導(dǎo)學(xué)與用
- Ruby on Rails敏捷開發(fā)最佳實(shí)踐
- 網(wǎng)絡(luò)布線與小型局域網(wǎng)搭建
- 網(wǎng)站前臺(tái)設(shè)計(jì)綜合實(shí)訓(xùn)
- Hadoop應(yīng)用開發(fā)基礎(chǔ)
- SQL Server數(shù)據(jù)庫(kù)應(yīng)用基礎(chǔ)(第2版)
- 簡(jiǎn)明學(xué)中文版Photoshop