Table width and line feed in Cells

Source: Internet
Author: User

Table width and line feed in Cells

I. To fix the total table width and the width of each column:

 

 

<Tableid = "Table1" style = "table-layout: fixed" border = "1">

 

Or in the script:

 

This. style. tablelayout = Fixed

 

 

Html

 

{Table-layout: slayout}

 

Scripting

 

Object. Style. tablelayout[ =Slayout]

 

 

Possible values:

 

 

Slayout

 

StringSet or obtain the following values:

 

Auto

 

By default, the column width is set to the maximum content width that cannot be separated.

 

Fixed

 

The table width and column width are fixed and do not change with the content in cells.

 

I. Set the width of each column without the table width: The table width is equal to the sum of the width of each column

 

2. Set the table width without the width of each column: the width of each column is evenly allocated.

 

3. If no width is set, the table width is 100%, and the width of each column is evenly allocated.

 

 

 

Ii. line feed Problems

 

<TD> there is an attribute called nowrap, which can be used to control whether line breaks are allowed for each cell.

 

 

<Tdnowrap = true>

 

Or

 

This. nowrap = true

 

 

Html

 

<Element Nowrap...>

 

Scripting

 

Object. Nowrap[ =Bwrap]

 

Possible values:

 

Bwrap

 

BooleanSet or obtain the following value :.

 

False

 

Default Value: allow the return of words and characters in a cell.

 

True

 

Cell Return rows are not allowed unless the characters contain "<br>"

 

 

 

Asp.net's DataGrid has a problem. Its column has an attribute itemstyle. WRAP is designed to be the itemstyle of this column. when the wrap attribute is true, the cell can return rows. If it is set to false, the returned rows are not allowed. However, when it is set to false, the output to the client is as follows:

 

<Tdnowrap = "nowrap">

 

Instead

 

<Tdnowrap = "true">

 

Therefore, the itemstyle. Wrap attribute does not work. manually add attribute: nowrap = true to the units that cannot be returned in the datagrid1_itemdatabound event.

 

Privatevoiddatagrid1_itemdatabound (objectsender, system. Web. UI. webcontrols. datagriditemeventargse)

 

{

 

E. Item. cells [N]. Attributes. Add ("nowrap", "true ");

 

}

 

 

3. forcibly return English Words

 

The preceding two methods can fix the table width and set whether each unit can return rows. Now, another problem may occur, when a long English word is allowed to return to the row, it may exceed the width of the cell. If the word is not truncated from it, the part of the word that exceeds the cell width is not displayed. Therefore, the word must be forcibly truncated back to the row where the length of the cell is exceeded.

 

We can use the word-Break style in CSS to achieve our goal:

 

 

<Tableid = "Table1" style = "table-layout: fixed; Word-break: Break-all" border = "1">

 

Or in the script:

 

This. style. wordbreak = Break-all

 

 

Html

 

{Word-break: sbreak}

 

Scripting

 

Object. Style. wordbreak[ =Sbreak]

 

Possible values:

 

Sbreak

 

StringSet or obtain the following value:

 

Normal

 

Default value. You can return rows from each word.

 

Break-all

 

The row is returned when the column width is exceeded, regardless of the position.

 

Keep-all

 

Return of Chinese, Japanese, and Korean is not allowed. This function is similar to the non-Asian version of "normal.

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.