(Solved - see solution via codepen link) I am trying to use an SVG image as a background that will always stretch to 100% of its parent div. Already tried:
- Use as CSS background-image and set background-size: 100% 100%.
- Put absolute to parent div and set height:100%.
- preserveAspectRatio="xMaxYMax".
- even if I manually change the viewBox it dosen't work.
- tried all the related questions I found here - Stretch SVG background image?, Automatically scale an SVG to its parent, Fit/Stretch SVG to div background without reescaling
To get better understanding of what I want, please visit this link:
http://185.127.16.178/~amen/%D7%90%D7%95%D7%91%D7%97%D7%A0%D7%AA-%D7%9C%D7%90%D7%97%D7%A8%D7%95%D7%A0%D7%94/
In that green bubble, the text's length can vary, so I need the SVG to stretch when more text is added and the div is growing.
I also created a small pen -
.svg-container {
height: 400px;
width: 200px;
border: 1px solid red;
position: relative;
}
#small_bubble {
top: 0;
right: 0;
width: 100%;
height: 100%;
}
.cls-1 {
fill: transparent;
stroke: green;
stroke-miterlimit: 3;
stroke-width: 3px;
}
.e-poa {
position: absolute;
}
e-por {
position: relative;
}
<div class="svg-container">
<svg id="small_bubble" class="e-poa" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 311.92 272.85" preserveAspectRatio="xMaxYMax">
<path class="cls-1" preserveAspectRatio="xMaxYMax" d="M301.52,1.57,8.37,19.53A7.87,7.87,0,0,0,1.5,27.34V214.76a7.89,7.89,0,0,0,7.12,7.85l46.67,4.53-7.14,42.78,63-37.35,190.58,18.51a7.88,7.88,0,0,0,8.65-7.85V9.38A7.88,7.88,0,0,0,301.52,1.57Z"/>
</svg>
</div>
Solution can be seen here (Solved by - @Furkan Poyraz): https://codepen.io/ncamaa/pen/JZzeQM
