简体   繁体   中英

CSS word-wrap property not working for label tag in Bootstrap

I have a quiz game setup on bootstrap. Here is the code:

<div class="col-md-12">
   <div class="row">
      <div class="col-md-12" style="padding-bottom:20px; text-align:center;">
         <h1>4 . In the three stage theory of memory, the first stage is called short-term memory.</h1>
      </div>
   </div>
   <div class="row">
      <div class="col-md-6">
         <label class="btn btn-primary" style="font-size:25px; width:100%;" id="label_4_A">
         <input type="radio" name="224" value="A" id="option_4_A"> TRUE                                 </label>
      </div>
      <div class="col-md-6">
         <label class="btn btn-primary" style="font-size:25px; width:100%;" id="label_4_B">
         <input type="radio" name="224" value="B" id="option_4_B"> FALSE                                    </label>
      </div>
   </div>
   <div class="row">
      <div class="col-md-6">
         <label class="btn btn-primary" style="font-size:25px; width:100%;" id="label_4_C">
         <input type="radio" name="224" value="C" id="option_4_C"> Partially True                                   </label>
      </div>
      <div class="col-md-6">
         <label class="btn btn-primary" style="font-size:25px; width:100%;" id="label_4_D">
         <input type="radio" name="224" value="D" id="option_4_D"> Partially False                                  </label>
      </div>
   </div>
   <hr>
   <input type="button" name="next2" value="Next" id="nt" onclick="hideandshow('4','5') " class="btn btn-success">  
   <input type="hidden" value="3" name="game_id">
</div>

The problem is with the label. When the label text is longer than the width of the column, the text disappears. I want it to break automatically and continue in new line. I tried using

<label class="btn btn-primary" style="font-size:25px; width:100%; word-wrap: break-word;" id="label_4_B">

But it doesn't seem to work with labels I believe. Would be greatful if I can get help from this community. Thank You.

You need to override the white-space property, which Bootstrap sets to nowrap on .btn :

 label.btn { white-space: initial; } .col-md-12 { width: 200px } 
 <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/> <div class="col-md-12"> <div class="row"> <div class="col-md-12" style="padding-bottom:20px; text-align:center;"> <h1>4 . In the three stage theory of memory, the first stage is called short-term memory.</h1> </div> </div> <div class="row"> <div class="col-md-6"> <label class="btn btn-primary" style="font-size:25px; width:100%;" id="label_4_A"> <input type="radio" name="224" value="A" id="option_4_A"> TRUE </label> </div> <div class="col-md-6"> <label class="btn btn-primary" style="font-size:25px; width:100%;" id="label_4_B"> <input type="radio" name="224" value="B" id="option_4_B"> FALSE </label> </div> </div> <div class="row"> <div class="col-md-6"> <label class="btn btn-primary" style="font-size:25px; width:100%;" id="label_4_C"> <input type="radio" name="224" value="C" id="option_4_C"> Partially True </label> </div> <div class="col-md-6"> <label class="btn btn-primary" style="font-size:25px; width:100%;" id="label_4_D"> <input type="radio" name="224" value="D" id="option_4_D"> Partially False </label> </div> </div> <hr> <input type="button" name="next2" value="Next" id="nt" onclick="hideandshow('4','5') " class="btn btn-success"> <input type="hidden" value="3" name="game_id"> </div> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM