S
S
spike3642014-08-06 13:24:32
css
spike364, 2014-08-06 13:24:32

How to shrink and adapt text when it doesn't fit in a block?

There is a block. It is filled with text on certain events. But with a large amount of text, it goes beyond the border and obscures the block that is nearby.
How to make text responsive? So that its size decreases when the div overflows?

Answer the question

In order to leave comments, you need to log in

6 answer(s)
G
Grigory Zhdanov, 2014-08-06
@grovas

I think you can use vh. For example:

.some-text {
    font-size: 100vh;
    line-height: 100vh;
}

Here is an article on habré

Y
Yuri Lobanov, 2014-08-06
@iiil

Example:
codepen.io/iiil/pen/yDbtL
When adding text, call the scale function. The step and minfs variables are the font size change step and the minimum font size. When the minimum is reached, a vertical scroll appears.

E
Evgeny Petrov, 2014-08-06
@Petroveg

Surrenders to me that the task is incorrect from the very beginning. What was wrong with scrolling?

B
barkalov, 2014-08-06
@barkalov

function onTextChange() {
    var textLength = $('.textHolder').text().length;
    var fontSize = Math.min(12, (1000 / textLength) * 12); 
    //where 12 - typical font-size, 1000 - typical length
    $('.textHolder').css('font-size', fontSize+'px');
{

This is with jQuery. On vanilla js you can rewrite it yourself.

V
Vitaly Zheltyakov, 2014-08-06
@VitaZheltyakov

Is this option not suitable?
htmlbook.ru/css/text-overflow

L
Lev Rozanov, 2014-08-06
@MetisKot

Responsive layout, how to change the font size when changing the block size?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question