Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap 4 - word wrapping in cards

How can I word wrap text insided cards.

Here's the problem: plunker link

Do you have any idea how to fix it?

like image 529
mskuratowski Avatar asked Feb 14 '17 17:02

mskuratowski


People also ask

How do I wrap text in bootstrap?

Use bootstrap text utilities to wrap or unwrap the text. Wrap text with a . text-wrap class. This text should wrap.

Which class is used to wrap around a group of cards in bootstrap?

The . card-deck class creates a grid of cards that are of equal height and width.

What is a card in Bootstrap 4?

Cards A card in Bootstrap 4 is a bordered box with some padding around its content. It includes options for headers, footers, content, colors, etc.

What is Bootstrap wrap?

Introduction of Wrap Bootstrap The bootstrap wrap is used to cover or wrap the flex items in a flex container.It has main three classes which is.flex-wrap,.flex-nowrap,.flex-wrap-reverse.First is.flex-wrap for wrapping flax content. Second is.flex-nowrap for no wrapping in flex container.

How do I make a card clickable in Bootstrap 4?

Cards. A card in Bootstrap 4 is a bordered box with some padding around its content. It includes options for headers, footers, content, colors, etc. ... Add the .stretched-link class to a link inside the card, and it will make the whole card clickable and hoverable (the card will act as a link): John Doe.

What version of material design for Bootstrap should I use?

We recommend migrating to the latest version of our product - Material Design for Bootstrap 5. Bootstrap cards are components which display content built of different elements with characteristic shadows, depth and hover effects. It is hard to think of a better way of displaying your content to users other than by using cards.


Video Answer


2 Answers

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="[email protected]" 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>
like image 92
andreas Avatar answered Oct 17 '22 19:10

andreas


Simple:

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

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

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

like image 4
Marian07 Avatar answered Oct 17 '22 19:10

Marian07