How can I reduce font size based on length?

后端 未结 2 2012
迷失自我
迷失自我 2021-01-18 07:55

Currently I have some large text on a page, and layout works fine for short text (~12-14 chars in length), but any more than that will overflow or wrap. This is undesirable,

2条回答
  •  说谎
    说谎 (楼主)
    2021-01-18 08:22

    FitText does work with a fluid width.

    From the github page :

    Make sure your container has a width! display: inline elements don't have a width. Use display: block OR display: inline-block+ a > specified width (i.e. width: 100%).

    Bold is mine for emphasis.

    Looking on the homepage for FitText also reveals that there are no fixed width units in sight.

    I should also mention that there is not a native CSS technique to achieve this. The closest thing would possibly be viewport relative lengths but that doesnt solve your problem.

    My additional opinion (danger beware) : In my experience when you are confronted with a problem like this, its because you may be looking at things a little wrong from the design side, And if you require Javascript for your layout to stay intact, I do think that needs to be reconsidered. Nursing a design along is usually better than banging it into place with a crowbar. End Opinion

提交回复
热议问题