CSS style wrap/force line wrapping

Source: Internet
Author: User

Write style encountered in the English characters beyond the container problem, degree Niang after understanding the following knowledge, share with you, at the same time so that their own future review.

One, automatic line-wrapping problem

It is reasonable to line up normal characters, while continuous numbers and English letters often hold the container large.

The following is how CSS implements the line wrapping method

For block-level elements such as Div,p
Line wrapping for normal text (Asian and non-Asian text) elements have default white-space:normal, and wrap after defined width
Html:

<div id= "Wrap" > Normal text wrap (Asian and non-Asian) elements have the default white-space:normal when defined </div>

Css:

#wrap {white-space:normal; width:200px;}

1. (IE) consecutive English characters and Arabic numerals, using Word-wrap:break-word; or word-break:break-all; implement force break

#wrap {word-break:break-all; width:200px;}

Or

#wrap {word-wrap:break-word; width:200px;}

Html:

<div id= "Wrap" >abcdefghijklmnabcdefghijklmnabcdefghijklmn111111111</div>

Effect: line wrapping can be implemented

2. (Firefox browser) consecutive lines of English characters and Arabic numerals, all versions of Firefox do not solve this problem, we only let the characters beyond the boundary hide or add a scrollbar to the container

#wrap {word-break:break-all; width:200px; overflow:auto;}

Html:

<div id= "Wrap" >abcdefghijklmnabcdefghijklmnabcdefghijklmn111111111</div>

Effect: Container normal, content hidden

For table

1. (IE) use table-layout:fixed; Force table width, excess content hidden

<table style= "table-layout:fixed" width= ">"
<tr>
<td>abcdefghigklmnopqrstuvwxyz1234567890ssssssssssssss</td>
</tr>
</table>

Effect: Hide Excess content

2. (IE) use table-layout:fixed, force the width of table, inner layer td,th adopt word-break:break-all; or Word-wrap:break-word; line break

<table width= "" "style=" table-layout:fixed; " >
<tr>
&LT;TD width= "25%" style= "Word-break:break-all; ">abcdefghigklmnopqrstuvwxy 1234567890</td>
&LT;TD style= "Word-wrap:break-word;" &GT;ABCDEFGHIGKLMNOPQRSTUVWXYZ 1234567890</td>
</tr>
</table>

Effect: can be changed line

3. (IE) nested div,p in td,th, etc. using the Div,p method mentioned above (tips)

4. (Firefox browser) use table-layout:fixed, force table width, inner layer td,th adopt word-break:break-all; or Word-wrap:break-word; line break, Use Overflow:hidden; hide beyond content, here Overflow:auto; not working

<table style= "table-layout:fixed" width= ">"
<tr>
&LT;TD width= "25%" style= "Word-break:break-all; Overflow:hidden; ">abcdefghigklmnopqrstuvwxyz1234567890</td>
&LT;TD width= "75%" style= "Word-wrap:break-word; Overflow:hidden; ">abcdefghigklmnopqrstuvwxyz1234567890</td>
</tr>
</table>

Effect: Hide more than content

Second,the CSS style force does not break the line

CSS Styles

Force No Line break

div{
White-space:nowrap;
}


Wrap Line

div{
Word-wrap:break-word;
Word-break:normal;
}

Force English words to break

div{
Word-break:break-all;
}

CSS settings do not change careers:

Overflow:hidden Hidden

White-space:normal Default

Pre line breaks and other whitespace characters are protected

NoWrap force all text to be displayed in the same line until the text ends or encounters a BR object

To set a forced line break:

Word-break:

normal; Allows word wrapping in words in Asian and non-Asian language text rules

Break-all: The behavior is the same as in Asian languages. Also allows non-Asian-language text lines to be broken within any word. This value is appropriate for Asian text that contains some non-Asian text

Keep-all: Same as normal for all non-Asian languages. For Chinese, Korean, Japanese, word break is not allowed. A high-resolution solution for non-Asian texts with small amounts of Asian text

No line break in English

Add Word-break:break-all to CSS and solve problems. This problem is only IE, under the FF test, FF can add their own scroll bar, so it does not affect the effect

Suggest you do skin, remember in body Riga Word-break:break-all; This can solve the problem of IE's frame being open in English

The following is a description of the Word-break, note that Word-break is a ie5+ proprietary property

Grammar:

Word-break:normal | Break-all | Keep-all

Parameters:

Normal: Allow line wrapping in words according to Asian and non-Asian language text rules

Break-all: The behavior is the same as in Asian languages. Also allows non-Asian-language text lines to be broken within any word. This value is appropriate for Asian text that contains some non-Asian text

Keep-all: Same as normal for all non-Asian languages. For Chinese, Korean, Japanese, word break is not allowed. Suitable for non-Asian texts containing small amounts of Asian text

Description

Sets or retrieves the word wrapping behavior of text within an object. Especially when multiple languages are present.

For Chinese, break-all should be used.

The corresponding script attribute is wordbreak.

Example: div {word-break:break-all;}

Reprinted from: http://blog.csdn.net/ye987987/article/details/8011875

CSS style wrap/force line wrapping

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.