Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@lightjs
Last active March 11, 2018 20:36
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lightjs/5372867 to your computer and use it in GitHub Desktop.
Save lightjs/5372867 to your computer and use it in GitHub Desktop.
SVG resize with non-scaling-stroke value for vector-effect attribute avoiding deformation on path stroke (cross browser)
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>SVG resize</title>
<style>
div, svg {
width:100%;
height:100%;
}
text {
font-family: 'Helvetica Neue', Verdana;
font-weight: 100;
font-size: 22px;
text-anchor: middle;
}
</style>
</head>
<body>
<div>
<svg>
<path d="M10,20L40,100L39,200z" stroke="black" stroke-width="2px" fill="none"></path>
<text transform="translate(50,240)">normal</text>
<path transform="translate(100,0)scale(4,1)" d="M10,20L40,100L39,200z" stroke="black" stroke-width="2px" fill="none"></path>
<text transform="translate(240,240)scale(4,1)">scaled</text>
<path vector-effect="non-scaling-stroke" transform="translate(300,0)scale(4,1)" d="M10,20L40,100L39,200z" stroke="black" stroke-width="2px" fill="none"></path>
<text transform="translate(450,240)">fixed</text>
</svg>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment