Moving <text> around within an svg element

garson

I am trying to overlay a element on an SVG graphic. For simplicity's sake, I have recreated it as just a rectangle with a text overlay. I am going to have some pretty serious formatting and styling on the text, but for now I am trying to figure out why I can't get it any lower on the page. I have tried changing the "x" and "y" on the element but it doesn't move at all. Can anyone help? I want to move the text lower in the yellow SVG rectangle.

Here is the full code:

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8" />
  <title>Title Here</title>
  <script data-require="[email protected]" data-semver="3.5.3" src="//cdnjs.cloudflare.com/ajax/libs/d3/3.5.3/d3.js"></script>
  <style type="text/css">

    ul {
        position:absolute;
     }
  </style>
</head>

<body>
  <p>Click me</p>
  <ul><text x="40" y="90">Test</text></ul>
  <script type="text/javascript">
    //Width and height
    var w = 500;
    var h = 300;
    var padding = 30;


    //Create SVG element
    var svg = d3.select("body")
      .append("svg")
      .attr("width", w)
      .attr("height", h)

      svg.append("rect")
        .attr("width", w)
        .attr("height", h)
        .attr("fill", "yellow");

  </script>
</body>

</html>
Weafs.py

text is an svg element and must be enclosed in an svg tag.

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8" />
  <title>Title Here</title>
  <script data-require="[email protected]" data-semver="3.5.3" src="//cdnjs.cloudflare.com/ajax/libs/d3/3.5.3/d3.js"></script>
  <style type="text/css">
    ul {
      position: absolute;
      padding: 0;
    }
  </style>
</head>

<body>
  <p>Click me</p>
  <ul>
    <svg width="500" height="300" viewBox="0 0 500 300">
      <text x="40" y="270">Test</text>
    </svg>
  </ul>
  <script type="text/javascript">
    //Width and height
    var w = 500;
    var h = 300;
    var padding = 30;


     //Create SVG element
    var svg = d3.select("body")
      .append("svg")
      .attr("width", w)
      .attr("height", h)

     svg.append("rect")
      .attr("width", w)
      .attr("height", h)
      .attr("fill", "yellow");
  </script>
</body>

</html>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Snap SVG - Moving a loaded element around

From Dev

Place tags around certain text within contenteditable without moving cursor

From Dev

Making SVG the equal width of <text> element within it

From Dev

Moving a canvas element around on webpage

From Dev

d3 Trying to select text within a svg text element

From Dev

text-anchor="start" not moving text element to the start of the svg element.

From Dev

text-anchor="start" not moving text element to the start of the svg element.

From Dev

Moving a SVG element in Firefox fails

From Dev

Moving a SVG element in Firefox fails

From Dev

Snake-Like Moving Glow around an element

From Dev

svg text translating and moving are not correct

From Dev

wrap element around span text

From Dev

Wrapping a text around a circular element

From Dev

Prevent browsers moving SVG elements around page breaks

From Dev

Getting anchor element within SVG

From Dev

Text element not showing on SVG

From Dev

is it possible to wrap an anchor tag around the circle element in an svg element?

From Dev

is it possible to wrap an anchor tag around the circle element in an svg element?

From Dev

Getting text around a specific element reference

From Dev

Add tags around selected text in an element

From Dev

Set span-element around text

From Dev

How to stop other elements moving around when moving an element from relative layout in android studio?

From Dev

text moving out of the element using transform rotate

From Dev

Matching text within a parent element

From Dev

Prevent text wrapping within an element

From Dev

Wrap text within element LXML

From Java

Inserting Text Next to SVG element

From Dev

SVG text element not positioning correctly

From Dev

Svg text element vertical flip

Related Related

  1. 1

    Snap SVG - Moving a loaded element around

  2. 2

    Place tags around certain text within contenteditable without moving cursor

  3. 3

    Making SVG the equal width of <text> element within it

  4. 4

    Moving a canvas element around on webpage

  5. 5

    d3 Trying to select text within a svg text element

  6. 6

    text-anchor="start" not moving text element to the start of the svg element.

  7. 7

    text-anchor="start" not moving text element to the start of the svg element.

  8. 8

    Moving a SVG element in Firefox fails

  9. 9

    Moving a SVG element in Firefox fails

  10. 10

    Snake-Like Moving Glow around an element

  11. 11

    svg text translating and moving are not correct

  12. 12

    wrap element around span text

  13. 13

    Wrapping a text around a circular element

  14. 14

    Prevent browsers moving SVG elements around page breaks

  15. 15

    Getting anchor element within SVG

  16. 16

    Text element not showing on SVG

  17. 17

    is it possible to wrap an anchor tag around the circle element in an svg element?

  18. 18

    is it possible to wrap an anchor tag around the circle element in an svg element?

  19. 19

    Getting text around a specific element reference

  20. 20

    Add tags around selected text in an element

  21. 21

    Set span-element around text

  22. 22

    How to stop other elements moving around when moving an element from relative layout in android studio?

  23. 23

    text moving out of the element using transform rotate

  24. 24

    Matching text within a parent element

  25. 25

    Prevent text wrapping within an element

  26. 26

    Wrap text within element LXML

  27. 27

    Inserting Text Next to SVG element

  28. 28

    SVG text element not positioning correctly

  29. 29

    Svg text element vertical flip

HotTag

Archive