Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making a very long word fit in responsive element?

I'm using Twitter Bootstrap.

<div class="container">
    <div class="row-fluid">
        <h1>VeryLongWordHere</h1>
    </div>
</div>

JSfiddle


On mobile screens the text becomes unreadable; leaving me with two options:

  1. Make the text size reduce when width gets to certain size (how do I do this BTW?)
  2. Make the text go over >1 lines; e.g.: on each segment I specify with <span> tags

However I'm not sure how to do either...

like image 877
stackoverflowuser95 Avatar asked Dec 05 '22 12:12

stackoverflowuser95


2 Answers

I use this CSS in my solution to a similar problem:

word-wrap:break-word

This will force words to break if necessary to force them to fit.

like image 139
Niet the Dark Absol Avatar answered Jan 08 '23 14:01

Niet the Dark Absol


For your first option, there are a number of jQuery plugins that dynamically resize text to fit the width of the parent element. Here are a few:

  • FitText
  • SlabText
  • BigText

You could use any of these plugins to resize the text when the screen size is smaller than a certain breakpoint. Something like this:

if (jQuery(window).width()) < 600) {
   jQuery('h1').slabText();
}
like image 22
Brett DeWoody Avatar answered Jan 08 '23 14:01

Brett DeWoody