简体   繁体   中英

Decreasing Font Size When Width Overflows Div

I believe my question is unique because I am using a counter whose width can constantly increase, as opposed to the container width changing, which is what seems to usually be asked.

My site is http://script-timer.com/ , and I am trying to decrease the font of the timer when it overflows its container div. Here is the javascript I am currently working on to accomplish this:

$(document).ready(function() {
    while( $('#scriptTime').width() > $('#timer-container').width() ) {
        $('#scriptTime').css('font-size', (parseInt($('#scriptTime').css('font-size')) - 1) + "rem" );
    } 
});

This looks like right to me, but being as I am very much still learning, I am most likely missing something simple. Is there a better way to accomplish this? Thank you for your help!

Here is a link to the plugin: https://plugins.jquery.com/textfill/ And a link to the source: http://jquery-textfill.github.io/

or

add this in css method

overflow: auto;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM