196

For the life of me I am unable to get these twitter bootstrap buttons to text wrap onto multiple lines, they appearing like so.

I cannot post images, so this is what it is doing...

[This is the bu] tton text

I would like it to appear like

[This is the ]

[button text ]

<div class="col-lg-3"> <!-- FIRST COL -->
  <div class="panel panel-default">
    <div class="panel-body"> 
    <h4>Posted on</h4>
    <p>22nd September 2013</p>
    <h4>Tags</h4>
    <a href="#" class="btn btn-primary btn-xs col-lg-12" style="margin-bottom:4px;">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</a>
   <a href="#" class="btn btn-primary btn-xs col-lg-12" style="margin-bottom:4px;">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</a>
   <a href="#" class="btn btn-primary btn-xs col-lg-12" style="margin-bottom:4px;">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</a>
           </div>
  </div>
</div>

Any help would be much appreciated.

Edit. I have tried adding word-wrap:break-word; but it is not making any difference.

Edit. JSFiddle http://jsfiddle.net/TTKtb/ - You will need it expand the right column so the panels sit next to one another.

General Grievance
  • 4,555
  • 31
  • 31
  • 45
M_Becker
  • 2,018
  • 2
  • 14
  • 11

4 Answers4

376

Try this: add white-space: normal; to the style definition of the Bootstrap Button or you can replace the code you displayed with the one below

<div class="col-lg-3"> <!-- FIRST COL -->
  <div class="panel panel-default">
    <div class="panel-body"> 
    <h4>Posted on</h4>
    <p>22nd September 2013</p>
    <h4>Tags</h4>
    <a href="#" class="btn btn-primary btn-xs col-lg-12" style="margin-bottom:4px;white-space: normal;">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</a>
   <a href="#" class="btn btn-primary btn-xs col-lg-12" style="margin-bottom:4px;white-space: normal;">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</a>
   <a href="#" class="btn btn-primary btn-xs col-lg-12" style="margin-bottom:4px;white-space: normal;">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</a>
           </div>
  </div>
</div>

I have updated your fiddle here to show how it comes out.

Brian Kinyua
  • 4,456
  • 1
  • 18
  • 17
  • Ahh, wow. Just looked it up. Didn't even know that CSS code existed. Thanks for your help! Spent hours trying to work this one out. – M_Becker Sep 25 '13 at 04:38
  • 4
    @user2063032 I think this guy can best explain white-space [link](http://www.impressivewebs.com/css-white-space/). – Brian Kinyua Sep 25 '13 at 04:42
  • No worries, I learn something each day from stackoverflow. Also you'll notice that the white-space property works well if the element i.e. the button is of a specified width. – Brian Kinyua Sep 25 '13 at 04:44
  • I am having this issue but with the panel title, how it an be fixed?? ideas – victor sosa Jul 03 '15 at 11:05
  • @victorsosa Kindly provide a fiddle with the code in question plus specify the element you're trying to manipulate – Brian Kinyua Jul 03 '15 at 12:04
74

You can simply add this class.

.btn {
    white-space:normal !important;
    word-wrap: break-word; 
}
Getsomepeaches
  • 1,041
  • 1
  • 10
  • 17
6

FWIW, in Boostrap 4.4, you can add .text-wrap style to things like buttons:

   <a href="#" class="btn btn-primary text-wrap">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</a>

https://getbootstrap.com/docs/4.4/utilities/text/#text-wrapping-and-overflow

hwjp
  • 15,359
  • 7
  • 71
  • 70
2

You can add these style's and it works just as expected.

.btn {
    white-space:normal !important; 
    word-wrap: break-word; 
    word-break: normal;
}
chickens
  • 19,976
  • 6
  • 58
  • 55
  • Using inline styles would only allow you to fix this for that one button. Add it to a class so you can use it throughout your project. Using a col definition in a class on an anchor would be seen as bad practice whilst using Bootstrap. – Getsomepeaches Apr 09 '19 at 00:32