22

How can I word wrap text insided cards.

Here's the problem: plunker link

Do you have any idea how to fix it?

Carol Skelly
  • 351,302
  • 90
  • 710
  • 624
mskuratowski
  • 4,014
  • 15
  • 58
  • 109
  • Hasn't this [already been asked before](http://stackoverflow.com/questions/18628038/break-long-word-with-css)? It's really a CSS issue and not specfic to Bootstrap. – Carol Skelly Feb 14 '17 at 18:30

4 Answers4

27

You need two rules:

  • max-width for your .card elements (because without defining a width CSS will not know where to break your long word) or overflow: hidden; to make the .card width no longer depend on the long word length
  • word-wrap: break-word; to tell the browser to break a word

.card {
    max-width: 100%;
}
.card-text {
    word-wrap: break-word;
}

.card {
  overflow: hidden;
}
.card-block {
  word-wrap: break-word;
}
<link data-require="bootstrap@4.0.0-alpha.6" data-semver="4.0.0-alpha.6" rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" />

  <div class="card-deck">
    <div class="card">
      <div class="card-block">
        <h4 class="card-title">Card title</h4>
        <p class="card-text">This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
        <p class="card-text"><small class="text-muted">Last updated 3 mins ago</small>
        </p>
      </div>
    </div>
    <div class="card">
      <div class="card-block">
        <h4 class="card-title">Card title</h4>
        <p class="card-text">This card has supporting text below as a natural lead-in to additional content.</p>
        <p class="card-text"><small class="text-muted">Last updated 3 mins ago</small>
        </p>
      </div>
    </div>
    <div class="card">
      <div class="card-block">
        <h4 class="card-title">Card title</h4>
        <p class="card-text">supportingsupportingsupportingsupportingsupportingsupportingsupportingsupportingsupportingsupportingsupportingsupportingsupportingsupportingsupportingsupportingsupportingsupportingto additional content. This card has even longer content than the
          first to show that equal height action.</p>
        <p class="card-text"><small class="text-muted">Last updated 3 mins ago</small>
        </p>
      </div>
    </div>
  </div>
andreas
  • 16,357
  • 12
  • 72
  • 76
4

Simple:

/* For screens above: 576px */
.card{
  overflow: hidden;
}

.card-text{
  word-wrap: break-word;
}

https://plnkr.co/edit/BEbJehY8hkWpDoTfFJXz?p=preview

Marian07
  • 2,303
  • 4
  • 27
  • 48
0

Also consider this (for URLs etc); from the docs:

For longer content, you can add a .text-truncate class to truncate the text with an ellipsis. Requires display: inline-block or display: block.

https://getbootstrap.com/docs/4.1/utilities/text/

Ben Collins
  • 455
  • 5
  • 7
0

For future reference, this would work too:

.card-text {
  overflow-wrap: anywhere;
  word-wrap: break-word;
  word-break: normal;
  hyphens: auto;
}

See this discussion for additional info.

ABC
  • 189
  • 9