I need to have a script that will adjust the width of the font size to fill the width of the parent. There maybe several containers with text withing that parent div. They are spaced from each other with an equal width margin.
So, somehow I need to iterate through font sizing, increasing the size by 1px and checking if the new width of all spans and their spacers fit within the parentContainer...
Here's what I've got so far.
<style>
span {
margin-right:20px
}
</style>
<div id="parentContainer">
<span>some text</span>
<span>more text</span>
<span>another text</span>
</div>
<script>
$("#parentContainer span:last-child").css("margin-right","0");
function adjustFonts() {
var myText = $("span").length, // count text containers
spacersWidth = (myText - 1) * 20, // margin on the right side
availWidth = $("myText").innerWidth(),
defaultFontSize = 11;
var fontSize = ???
$("myText").css("font-size", fontSize +"px");
}
adjustFonts();
$(window).resize(function() {
adjustFonts();
});
</script>