我需要一个脚本来调整字体大小的宽度以填充父级的宽度。可能有几个容器带有该父 div 的文本。它们以相等的宽度边距彼此隔开。
所以,我需要以某种方式迭代字体大小,将大小增加 1px 并检查所有跨度的新宽度及其间隔符是否适合 parentContainer ......
这是我到目前为止所得到的。
<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>