web-dev-qa-db-ja.com

テーブルセル<td>の内容を強制的に折り返すにはどうすればよいですか?

ページ全体を表示します* wrappableはmain.cssファイルで定義されています

/* Wrappable cell
* Add this class to make sure the text in a cell will wrap.
* By default, data_table tds do not wrap.
*/
td.wrappable,
table.data_table td.wrappable {
    white-space: normal;
}                

ページ全体をヘレスします。

<%@ include file="../../include/pre-header.html" %>
<form id="commentForm" name="commentForm" action="" method="post">



    <ctl:vertScroll height="300" headerStyleClass="data_table_scroll" bodyStyleClass="data_table_scroll" enabled="${user.scrollTables}">
        <ctl:sortableTblHdrSetup topTotal="false" href="show.whatif_edit_entry?   entryId=${entry.entryId}" />
        <table class="data_table vert_scroll_table">



            </tr>
            <tr>
                <ctl:sortableTblHdr styleClass="center" title="Comments" property="comment" type="top">Comments</ctl:sortableTblHdr>
            </tr>


            <c:forEach var="comments" items="${entry.comments}">


                <tr id="id${comments.id}">
                    <td id="comments-${comments.id}" class="wrappable" style="width:400px;">${comments.comment}</td>
                </tr>



            </c:forEach>
            <c:if test="${lock.locked || form.entryId < 0 }">
                <%-- This is the row for adding a new comment. --%>
                    <tr id="commentRow">
                        <td><input type="text" id="comment" name="comment" size="50" maxlength="250" onkeypress="javascript:return noenter();" />
                            <a href="javascript:addComment();"><img src="../images/icon_add.gif" border="0" alt="Add"/></a>
                        </td>

                    </tr>
            </c:if>

        </table>

    </ctl:vertScroll>
</form>

それは私が提出するたびに広がるだけです。
このページはdivの範囲内です。 divとテーブルの幅も設定する必要がありますか?

138
Doc Holiday

テーブルにtable-layout:fixedを、tdにWord-wrap:break-Wordを使用してください。

この例を参照してください。

<html>
<head>
   <style>
   table {border-collapse:collapse; table-layout:fixed; width:310px;}
   table td {border:solid 1px #fab; width:100px; Word-wrap:break-Word;}
   </style>
</head>

<body>
   <table>
      <tr>
         <td>1</td>
         <td>Lorem Ipsum</td>
         <td>Lorem Ipsum is simply dummy text of the printing and typesetting industry. </td>
      </tr>
      <tr>
         <td>2</td>
         <td>LoremIpsumhasbeentheindustry'sstandarddummytexteversincethe1500s,whenanunknown</td>
         <td>Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</td>
      </tr>
      <tr>
         <td>3</td>
         <td></td>
         <td>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna...</td>
      </tr>
   </table>
</body>
</html>

デモ:

table {border-collapse:collapse; table-layout:fixed; width:310px;}
       table td {border:solid 1px #fab; width:100px; Word-wrap:break-Word;}
       <table>
          <tr>
             <td>1</td>
             <td>Lorem Ipsum</td>
             <td>Lorem Ipsum is simply dummy text of the printing and typesetting industry. </td>
          </tr>
          <tr>
             <td>2</td>
             <td>LoremIpsumhasbeentheindustry'sstandarddummytexteversincethe1500s,whenanunknown</td>
             <td>Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</td>
          </tr>
          <tr>
             <td>3</td>
             <td></td>
             <td>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna...</td>
          </tr>
       </table>
    
265
jim31415

それは私のために働きます。

<style type="text/css">

 td {

    /* css-3 */
    white-space: -o-pre-wrap; 
    Word-wrap: break-Word;
    white-space: pre-wrap; 
    white-space: -moz-pre-wrap; 
    white-space: -pre-wrap; 

}

そしてテーブル属性は次のとおりです。

table { 
  table-layout: fixed;
  width: 100%
}
41
td {
overflow: hidden;
max-width: 400px;
Word-wrap: break-Word;
}
12
Jafstar

Bootstrapレスポンシブテーブルを使用している場合は、特定の列の最大幅を設定してテキストを折り返すだけで、この列のスタイルも次のようになります。

max-width:someValue;
Word-wrap:break-Word
4
Feng Han

ファイルパス名のように長い文字列があり、(スラッシュのように)特定の文字で文字列を分割したいだけの場合は、これが問題に取り組む別の方法です。 HTMLのスラッシュの直前(または直後)に Unicodeゼロ幅スペース の文字を挿入できます。

0
Mark Lakata

列を修正したい場合はwidthを設定してください。例えば:

<td style="width:100px;">some data</td>

0
Evgeniy

テーブルクラスにWord-break: break-Word;を追加するだけです。

0

これは私がセル内に "きれいな" JSONを表示する必要があるときに私には役に立ちました:

td { white-space:pre }

white-spaceプロパティ の詳細:

  • normal:この値は、空白のシーケンスを折りたたみ、必要に応じて改行して行ボックスを埋めるようにユーザーエージェントに指示します。

  • pre:この値は、ユーザーエージェントが空白のシーケンスを折りたたむのを防ぎます。
    行は、保存されている改行文字でのみ分割されます。

  • nowrap:この値は、normalと同様に空白を折りたたみますが、テキスト内の改行を抑制します。

  • pre-wrap:この値はユーザーエージェントが空白のシーケンスを折りたたむのを防ぎます。
    行は保存された改行文字で、そして必要に応じて行ボックスを埋めるために分割されます。

  • pre-line:この値はユーザーエージェントに空白のシーケンスを縮小するように指示します。
    行は保存された改行文字で、そして必要に応じて行ボックスを埋めるために分割されます。

(また、 ソース で詳細を参照してください。)

0
ashleedawg
.wrappable { 
      overflow: hidden; 
      max-width: 400px; 
      Word-wrap: break-Word; 
}

ここではバイナリデータとその動作についてテストしました。

0
jaip