javascript - SVG with viewBox and width is not scaling height correctly in IE -


I am trying to create inline SVG with viewBox attributes, but there are no clear width or height attributes. I'm setting the width of SVG to 100% using CSS. From this, the SVG scale should maintain its wrapping container, the aspect ratio set by the view box. In Chrome and Firefox, it works perfectly!

Here's a minimal coding example of what I'm talking about:

HTML:

    

CSS:

  div {width: 400px; } SVG {width: 100%; Maximum-height: 100%; Profile: 1px solid tomato; } Text {font-size: 10px; }   

The view box is 100x10 The outer div is set to 400px width. This means that the height of SVG (and in Chrome / Firefox) should be 40px. But, in IE 11, the width is always 150px (even when the width of the div is greater than 1500px ...)

Is there a good way to fix this in IE? Why can not IE handle unknown height correctly? I can use the "move", but it is super ugly, another dome element is required, and every time I change the size of the cover, then the padding-top has to be added again.

For more information, why do I have to do this, I have written a quick blog post about it:

Thanks for the help! Some browsers (IE and Safari) will use SVG to use a default size if you have a certain height and Do not put the width that what is happening here is right for you, "internal aspect ration" requires any other dom and CSS and if we can finish it, it would be nice.

It's a solution, you can calculate and padding to the right height - You want Chatt and this right "unknown height". You can see a complete solution here:

  & lt ;! - xMidYMin: Align the midpoint x value of the view box of the element with the midpoint x value of the viewport. Piece: The entire viewport is covered by the view box and the view box becomes as small as possible, height: if you do not set; = 1px Some browsers will not render anything - & gt; & Lt; Div & gt; & Lt; Svg viewbox = "0 0 100 10" preserveAspectRatio = "xMidYMin piece" width = "100%" style = "height: 1px; overflow: visible; / * without JS: padding-bottom: 55% * /" & gt; & Lt; Text & gt; Hello & lt; / Text & gt; & Lt; / Svg & gt; & Lt; svg viewbox = "0 0 100 10" preserveAspectRatio = "xMidYMin piece" width = "100%" style = "height: 1px; overflow: view;" & Gt; & Lt; Text & gt; Age & lt; / text & gt; & Lt; / Svg & gt; & Lt; / Div & gt;   

and javascript:

  / * Here we do the hack. Mathematics Type: With percent / height / width we can adjust the total height of an element depending on the width using the padding-bottom if you want in html, you can insert inline padding-down. * / $ (Function () {$ ('SVG'). Each (function () {var svg = $ (this); var text = svg.find ('text'); var bbox = text.get (0) .getBBox (); // hack variety calcString = "calc (100% *" + bbox.height / bbox.width + ")"; svg.css ("padding-bottom", calcString); svg.get (0) .setAttribute ('View Box', [bbox.x, bbox.y, bbox.width, bbox.height]. Add (''));});});    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -