Reputation: 618
I there any possible way to change/select SVG
xy coordinates using css?
For example:
<svg class="line line-1" width="700" height="500">
<line x1="120" y1="330" x2="1000" y2="750" stroke="#ffffff"/>
</svg>
I want to change xy coordinates whit media query in css.
Upvotes: 2
Views: 1938
Reputation: 273086
You can apply a translation with CSS to change the coordinates of your line. Here is an example where I made the line to start from (0,0)
:
svg {
background:red;
}
svg line {
transform:translate(-120px,-330px);
}
<svg class="line line-1" width="700" height="500">
<line x1="120" y1="330" x2="1000" y2="750" stroke="#ffffff"/>
</svg>
And if you will have many elements you can group them inside a g
orn where you apply the needed transformation as you can also consider rotation, scale, etc:
svg {
background: red;
}
svg g.coord {
transform: translate(-120px, -330px);
}
<svg class="line line-1" width="700" height="500">
<g class="coord">
<line x1="120" y1="330" x2="1000" y2="750" stroke="#ffffff"/>
<line x1="120" y1="330" x2="300" y2="650" stroke="blue"/>
<line x1="120" y1="330" x2="180" y2="650" stroke="green"/>
</g>
</svg>
Upvotes: 4