CSS implementation table fixed width, more than the contents of the cell omitted

Source: Internet
Author: User

The width of the <table> cell is self-adapting to the size of the content, and the place is squeezed together without content. You need to fix the table width and the width of each column.

Table-layout:fixed

In a fixed table layout, the horizontal layout depends only on the table width, column width, table border width, cell spacing, and the contents of the cell.

White-space:nowrap; Text-overflow:ellipsis; Overflow:hidden;

Text that exceeds the specified length is displayed as an ellipsis.

1 <!DOCTYPE HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/TR/xhtml1/DTD/ Xhtml1-transitional.dtd ">2 <HTMLxmlns= "http://www.w3.org/1999/xhtml">3 <Head>4 <Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" />5 <title>Test</title>6 <style>7 * {8 padding:0;9 margin:0;Ten } One Table{ A width:300px; - Table-layout:fixed; - } the . First_col{ - White-space:nowrap;Text-overflow:ellipsis;Overflow:Hidden; - width:150px; - } + . First_col_text{ - White-space:nowrap;Text-overflow:ellipsis;Overflow:Hidden; + Color:Red; A width:120px; at float: Left; -  - } - img{ - width:20px; - Height:20px; in float: Right; - Margin-right:5px; to } + . Second_col{ - White-space:nowrap;Text-overflow:ellipsis;Overflow:Hidden;     the width:100px; * } $ . Third_col{Panax Notoginseng White-space:nowrap;Text-overflow:ellipsis;Overflow:Hidden; - width:50px; the } + </style> A </Head> the <Body> + <TableBorder= "1"cellspacing= "0"cellpadding= "0"> -   <TR> $     <TDclass= "First_col"> $         <Divclass= "First_col_text">123456789012345</Div> -         <imgsrc= "http://tb2.bdstatic.com/tb/editor/images/face/i_f23.png?t=20131111"> -     </TD> the     <TDclass= "Second_col">12345678901234567890123456789012345678901234567890</TD> -     <TDclass= "Third_col">1</TD>Wuyi   </TR> the   <TR> -     <TDclass= "First_col"></TD> Wu     <TDclass= "Second_col"></TD> -     <TDclass= "Third_col">12345678901234567890123456789012345678901234567890123456789012345678901234567890</TD> About   </TR> $   <TR> -     <TDclass= "First_col">123456789012345</TD> -     <TDclass= "Second_col"></TD> -     <TDclass= "Third_col"></TD> A   </TR> + </Table> the </Body> - </HTML>

Display effect:

CSS implementation table fixed width, more than the contents of the cell omitted

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.