How to scale text size compared to container

前端 未结 4 1551
挽巷
挽巷 2021-01-24 06:43

How would you scale text size based on container size. Other questions state it can\'t be done with css, if not how would you go about it?

4条回答
  •  遥遥无期
    2021-01-24 07:10

    I couldn't work out how to do it with CSS, so I used pure JS (don't need jquery).

    var els = document.getElementsByClassName('abc')
    for (var i = 0; i < els.length; i++){
        els[i].style.fontSize = els[i].clientHeight + 'px'
    }
    

    Example: http://jsfiddle.net/nickg1/H64mQ/

提交回复
热议问题