Positioning SVG elements using CSS

后端 未结 7 1887
野性不改
野性不改 2020-12-29 01:14

Assume the following svg document:




        
相关标签:
7条回答
  • 2020-12-29 02:04

    Use css positioning:

    index.html

    <link href="style.css" rel="stylesheet" />
    <div class="parent">
      <div class="child">
        <svg version="1.1" baseProfile="full" width="300" height="200" xmlns="http://www.w3.org/2000/svg"><text x="20" y="20">My text</text>
        </svg>
      </div>
    </div>
    

    style.css

    .parent {
      position: relative;
      height: 1000; /* bigger than your svg */
      width: 1000; /* bigger than your svg */
    }
    
    .child {
      position: absolute;
      top: 10px;  /* relative to parent container */
      left: 10px; /* relative to parent container */
    }
    
    0 讨论(0)
提交回复
热议问题