Skip to content

Instantly share code, notes, and snippets.

@mathisonian mathisonian/svg-sizing.js

Last active Jan 27, 2016
What would you like to do?
// This can be generalized to arbitrary
// aspect ratios. See last example for
// more on that.
// See calculation for total size in
// example above
var size = 202;
// 1st example - set an explicit
// width and height'#example-1')
.attr('width', size)
.attr('height', size);
// 2nd example - viewbox'#example-2')
.attr('width', '100%')
.attr('viewBox', '0 0 ' + size + ' ' + size);
// Note: all subsequent code inside of the
// viewbox SVG can still assume a width
// and height of 202, and it will automatically
// scale correctly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.