Analysis on automatic line feed of Div and table exceeding the width in CSS webpage Layout

Source: Internet
Author: User
Tags arabic numbers
Automatic line feed is a reasonable line feed for normal characters. Continuous numbers and English characters often increase the container size, which is a headache. Article Now, let's summarize how CSS implements line feed. As long as the following sentence is defined in CSS, the web page will not be supported.

For Div, P, and other block-level elements
The normal text line feed (Asian text and non-Asian text) element has the default white-space: Normal, automatically wrap after the defined width

Example source code [Www.52css.com] Html
<Div id = "Wrap"> normal Text wrap (Asian text and non-Asian text) elements have the default white-space: normal, when defined </div>
CSS
# Wrap {white-space: normal; width: 200px ;}

IE browser
Use Word-wrap: Break-word; or word-break: Break-all; to forcibly disconnect a row.

Example source code [Www.52css.com] Html
<Div id = "Wrap"> 52csscom52csscom52csscom52csscom52csscom52csscom </div>
CSS
# Wrap {word-break: Break-all; width: 200px ;}

Or

Example source code [Www.52css.com] # Wrap {word-wrap: Break-word; width: 200px ;}

Firefox
Continuous disconnection of English characters and Arabic numbers. None of Firefox versions solve this problem. In this case, we only need to hide the characters that exceed the boundary or add a scroll bar to the container.

Example source code [Www.52css.com] Html
<Div id = "Wrap"> 52csscom52csscom52csscom52csscom52csscom52csscom </div>
CSS
# Wrap {word-break: Break-all; width: 200px; overflow: auto ;}

For Table Elements

IE browser

1. Use table-layout: fixed; to force the table width and hide unnecessary content.

Example source code [Www.52css.com] <Table Style = "table-layout: fixed" width = "200"> <tr> <TD> 52csscom52csscom52csscom52csscom52csscom52csscom </TD> </tr> </table>

2. Use table-layout: fixed; to force the width of the table, use Word-break: Break-all in the TD and th layers, or use Word-wrap: Break-word.

Example source code [Www.52css.com] <Table width = "200" style = "table-layout: fixed;"> <tr> <TD width = "25%" style = "word-break: Break-all; "> keys </TD> <TD style =" word-wrap: Break-word; "> 52csscom52csscom52csscom52csscom52csscom52csscom </TD> </tr> </table>

3. nested Div and P in TD and th adopt the wrap method of Div and P mentioned above

Firefox

1. Use table-layout: fixed to force the width of the table, and use Word-break: Break-all; or word-wrap: Break-word to wrap the line, use overflow: hidden; hide the content beyond the upper limit. Here overflow: auto; cannot work.

Example source code [Www.52css.com] <Table Style = "table-layout: fixed" width = "200"> <tr>
<TD width = "25%" style = "word-break: Break-all; overflow: hidden;"> 52csscom52csscom52csscom52csscom52csscom52csscom </TD>
<TD width = "75%" style = "word-wrap: Break-word; overflow: hidden;"> 52csscom52csscom52csscom52csscom52csscom52csscom </TD>
</Tr> </table>

2. nesting Div and P in TD and th adopts the methods mentioned above to deal with Firefox.
Best CSS definition line feedCode 

Example source code [Www.52css.com] . Wrap {table-layout: fixed; Word-break: Break-all; overflow: hidden ;}
Related Article

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.