Ответ 1
Некоторые браузеры (IE и сафари) будут использовать размер по умолчанию для SVG, если вы не установите определенную высоту и ширину. Это то, что здесь происходит. Вы правы, "внутреннему аспекту рациона" требуется еще один Dom и css, и будет приятно, если мы сможем преодолеть это.
Есть решение для этого, вы можете вычислить и поместить правильную высоту в padding-bottom, и это даст правильную "неизвестную высоту", которую вы хотите. Вы можете увидеть полное решение здесь: http://codepen.io/tomkarachristos/pen/GZPbgZ
<!--
xMidYMin: Align the midpoint X value of the element viewBox with the midpoint X value of the viewport.
slice : the entire viewport is covered by the viewBox and the viewBox is scaled down as much as possible,
height: if you dont set >= 1px some browsers will not render anything.
-->
<div>
<svg viewBox="0 0 100 10" preserveAspectRatio="xMidYMin slice"
width="100%" style="height: 1px;overflow: visible;
/*without js:padding-bottom:55%*/"><text>hello</text>
</svg>
<svg viewBox="0 0 100 10" preserveAspectRatio="xMidYMin slice"
width="100%" style="height: 1px;overflow: visible;"><text>Age</text>
</svg>
</div>
и javascript:
/*
Here we do the hack.
With the math type: percent * height/width
we are adjust the total height of an element who is depend in width using the padding-bottom.
You can put an inline padding-bottom if you want in html.
*/
$(function() {
$('svg').each(function() {
var svg = $(this);
var text = svg.find('text');
var bbox = text.get(0).getBBox();
//the hack
var calcString = "calc(100% * " + bbox.height/bbox.width + ")";
svg.css("padding-bottom",calcString);
svg.get(0).setAttribute('viewBox',
[bbox.x,
bbox.y,
bbox.width,
bbox.height].join(' '));
});
});