There are quite a few questions on how to size or scale SVG elements within a page already, but none of them addressed sizing an SVG so it fills exactly the remaining available space within its parent - a <div> with id="content" which already contains some paragraphs (or other elements).
Target platforms include desktop browsers and mobile apps (using Cordova in case that matters).
I am using D3.js for drawing the SVG contents, so I don't want to use the SVG viewBox attribute (which is explained nicely in this answer) because that would also scale stroke widths which I'd like to have under direct CSS/JavaScript control.
Here is what I have so far: http://codepen.io/friendfx/pen/OMxYrL
This works quite well across modern desktop browsers but has the following problems:
- When reducing the window size such that the SVG element should become smaller than 300px in width or 150px in height (which I nowhere specified but which seems to be some sort of "default SVG size"), the layout starts to fall apart in Chrome and IE and (to a lesser extent Firefox which seems to have only problems with the 150px height).
- IE doesn't want to wrap the first (long) paragraph as long as the
body'sflex-directionisrow. - On Android the height of the SVG element seems to always equal the WebView's height, irrespective of the vertical space taken up by the two
<p>elements before the<svg>.
While I could potentially ignore issues 1 and 2, the 3rd one is a killer as I don't want any scrolling whatsoever.
After reading the SVG Specification on intrinsic sizing, I am wondering whether the WebView's behaviour is actually closest to the spec since it makes the SVG (at least vertically) grow to the SVG viewport's size (which I believe to be the size of the WebView/browser window).
Is there a reasonably clean way to solve (at least) issue 3?
By the way, here is a fork of the above code where I just replaced the <svg> element with a <p> and which works beautifully across all browsers and the Android WebView.