Search code examples
csstwitter-bootstraptwitter-bootstrap-3word-wrap

How to wrap long word inside container using Twitter Bootstrap 3?


This is my html:

<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

<div class="container-fluid">
    <div class="row post img-rounded">
        <span>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</span>
    </div>
</div>

The issue is, the end user selects what is inside the span. If the content inside the span is a very long word, then a horizontal scroll bar appears and the word extends outside of the div. Is there a non-hacky (possibly Twitter Bootstrap 3) way of basically wrapping the word so that it does not extend outside of the div, causing a horizontal scrollbar?

If not, what's the best way to solve the issue?


Solution

  • To break, use word-wrap: break-word, but you are missing the bootstrap col-*-* wrapping the span

    .row div {
      background: red
    }
    .row:first-of-type span {
      word-wrap: break-word
    }
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
    <div class="container-fluid">
      <div class="row post img-rounded">
        <div class="col-xs-2">
          <span>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</span>
        </div>
      </div>
      <hr />
      <div class="row post img-rounded">
        <div class="col-xs-2">
          <span>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</span>
        </div>
      </div>
    </div>