2016-10-15 16 views
3

テーブルの最大幅を設定しようとしていますが、動作していないようです。テーブル内の単語が長すぎると、テーブルの幅が自動的に拡大されます。どのように私は起こってからそれを停止し、代わりに次の行に行くにはあまりにも長い言葉を持っているのですか?テーブルの最大幅を設定する

<style> 
 
table { 
 
max-width: 300px; 
 
} 
 
table,td { 
 
border: 1px solid red; 
 
} 
 
div { 
 
border: 1px solid blue; 
 
word-wrap: break-word; 
 
} 
 
</style>
<table> 
 

 
<tr> 
 
<td> 
 
<div> hellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohello </div> 
 
</td> 
 
</tr> 
 

 
</table>

+0

「最大幅」を「td」にも追加します。 https://jsfiddle.net/2kcc59o6/ – Swordys

答えて

0

次のルールあなたを追加します。 CSSセクション。 divの内側にMAX-wdithを置く

div{ 
    overflow-wrap: break-word; 
    max-width: 300px; 
0

は=問題を解決します)

<style> 
 
table,td { 
 
border: 1px solid red; 
 
} 
 
div { 
 
border: 1px solid blue; 
 
word-wrap: break-word; 
 
max-width: 300px; 
 
} 
 
</style>
<table> 
 

 
<tr> 
 
<td> 
 
<div> hellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohello </div> 
 
</td> 
 
</tr> 
 

 
</table>

0

word-wrap: break-word;あなたは、コンテナに割り当てられた幅を持っている場合、あなたはこのプロパティを適用している動作します。したがって、または希望の幅をdivタグに割り当てる必要があります。

<style type="text/css"> 
    div { 
     width: 100px; /* this will limit the length of the word to 100px */ 
     border: 1px solid blue; 
     word-wrap: break-word; 
     } 
</style> 
関連する問題