Bootstrap 4 - word wrap on cards

How can I stack nested text cards.

Here's the problem: plunker link

Do you have an idea how to fix it?

+4
source share
2 answers

You need two rules:

  • max-widthfor your elements .card(because without determining the width, CSS will not know where to break your long word) or overflow: hidden; so that the width .cardno longer depends on the length of the long word
  • word-wrap: break-word;to tell the browser to break the 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>
Run codeHide result
+9
source

Plain:

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

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

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

+1
source

Source: https://habr.com/ru/post/1669727/


All Articles