2016-11-19 86 views
0

我有一個頁面顯示從mysql數據庫中檢索到的文本。如何將文本保存在div中?

我不明白爲什麼我不能讓文本顯示爲div內的文本塊。相反,它溢出了div。 (我使用自舉3)這是一個fiddle

<div class="container"> 
 
    <div class="row"> 
 
    <!---MAIN COLUMN------> 
 
    <div class="col-xs-12 col-md-6 col-sm-8 col-lg-6 col-centered"> 
 
     <h2> 
 
     How to keep the text inside the div? 
 
     </h2> 
 

 
     <div class="mytext"> 
 
     fdsnkfhskghkgskghsdkghdskghdsklhgkdlsghds 
 
     khgkdshgdksghdsklghdskg hkdslhgkdshgkdshgkdshgkd 
 
     shgksdlhgksdhgkdslhgkdshgkdshgkdshgksd hgkldshgkd 
 
     shgkldshgkhdsgkhdskghdskhgkdlshgkdshgkldsh 
 
     gkdshgklhds kghdskghdskl 
 
     <small> 
 
     </small> 
 

 
     </div> 
 

 
    </div> 
 
    </div> 
 
</div>

+0

可能重複的[如何在DIV中強制換行符中的換行符?](http://stackoverflow.com/questions/3058866/how-to-force-a-line-break-in-a -loooooong字-IN-A-DIV) – Dez

回答

4

用於word-break:break-all;這個詞

打破

.mytext{ 
 
    word-break:break-all; 
 
}
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/> 
 
<div class="container"> 
 
    <div class="row"> 
 
    <!---MAIN COLUMN------> 
 
    <div class="col-xs-12 col-md-6 col-sm-8 col-lg-6 col-centered"> 
 
     <h2> 
 
     How to keep the text inside the div? 
 
     </h2> 
 

 
     <div class="mytext"> 
 
     fdsnkfhskghkgskghsdkghdskghdsklhgkdlsghds 
 
     khgkdshgdksghdsklghdskg hkdslhgkdshgkdshgkdshgkd 
 
     shgksdlhgksdhgkdslhgkdshgkdshgkdshgksd hgkldshgkd 
 
     shgkldshgkhdsgkhdskghdskhgkdlshgkdshgkldsh 
 
     gkdshgklhds kghdskghdskl 
 
     <small> 
 
     </small> 
 

 
     </div> 
 

 
    </div> 
 
    </div> 
 
</div>

1

給予CSS來

.mytext{ 
    width:200px; 
    word-wrap:break-word; 
    border:thin black solid; 
} 

這裏更新JSFiddle

0

這純粹是一個假設性的問題 - 在一個真正的網站,你將有真正的文本由它比你的榜樣幻想字/秒更短的真實的話,他們將配合很好進入該div,因爲文本將在單詞末尾處斷開,即空格。只要使用相同的真實文字,你會看到。

相關問題