NOTE: This is not a duplicate of questions like this. I saw those and fixed my viewbox
attribute to be viewBox
. That led to the question I have here.
I am trying to build an SGF (Smart Game Format) editor using Angular 4 to practice the technology. I want the app to be responsive so I can use it nearly as well on a smartphone as I can on a desktop, so I similarly want the graphics to be responsive. It seemed that SVG would be a good choice (what with "scalable" being in the name), so I experimented until I got some effects I liked:
Here is a JSFiddle of the full-size starting point.
Before copying this into my Angular application, I did some research to determine whether I would need to do anything else to make my SVG responsive. CreativeBlog stated that I would need to replace my width
and height
attributes with a viewBox
attribute, so I did so. I also noted the following paragraph, but decided not to eliminate by constant references to millimeters as units:
First, unless there are compelling reasons to do otherwise, set measurements to 'pixels' in your vector tool. While it doesn't matter to SVG (which will measure the viewBox and elements happily in almost any measurement system) it makes sense to develop the SVG drawing using common CSS units, rather than the print default of inches; and it also makes it much easier to add @media queries and other interventions later.
I ran my Angular application, and was surprised to see this fairly useless view:
Here is a JSFiddle that shows the slight modification.
After several misadventures in fixes using preserveAspectRatio
, inserting an svg
prefix for the SVG namespace, and trying to find an Angular approach to resize the image, I tried surrendering by removing all the millimeter unit designations. The result was one step forward, two steps back: the image was now mostly responsive (it still is not adjusting for the available height correctly), but in turn my filters for the board and stone textures were ruined:
How can I get a SVG that will responsively resize as I need while still having the filters that seem to require my millimeter resolution work?
And, while I am willing to ask a new question for what may be a separate issue, if someone knows how to make the width adjust for the available screen height the way it looks like preserveAspectRatio
is supposed to, I would appreciate it if that one slipped that answer in, too :)