Line-wrap (Word-wrap) in CSS

Source: Internet
Author: User
  1. Div
    1. IE
      1. White-space: normal (standard)

        Example:

        # Wrapdiv {white-space: normal; width: 100px ;}

        <Div id = "wrapdiv"> timeislifetimeislifetimeislifetimeislifetimeislifetimeislifetimeislife </div>

      2. Word-break: Break-All (got from word)

        Example:

        # Wrapdiv {
        Word-break: Break-all; width: 100px ;}

        <Div id = "wrapdiv"> timeislifetimeislifetimeislifetimeislifetimeislifetimeislifetimeislife </div>

    2. Firefox

      There is no better solution, the solution is similar to IE, just add a overflow: hidden or overflow: auto. For instance:

      1.  

        # Wrapdiv {white-space: normal; width: 100px; overflow: hidden
        }

        <Div id = "wrapdiv"> timeislifetimeislifetimeislifetimeislifetimeislifetimeislifetimeislife </div>

      2.  

        # Wrapdiv {
        Word-break: Break-all; width: 100px; overflow: hidden
        }

        <Div id = "wrapdiv"> timeislifetimeislifetimeislifetimeislifetimeislifetimeislifetimeislife </div>

       

  2. Table
    1. IE: Table-layout: Fixed + nowrap (optional)
      1. Example1:

        <Style type = "text/CSS">

        . Tableautowrap1

        {

        Table-layout: fixed;

        }

         

        </Style>

         

        <Table class = "tableautowrap1" width = "100">

        <Tr> <TD>

        </TD> timeislifetimeislifetimeislife are you sure </tr>

        </Table>

      2. Example2:

        <Style type = "text/CSS">

        . Tableautowrap1

        {

        Table-layout: fixed;

        }

         

        </Style>

         

        <Table class = "tableautowrap1" width = "100">

        <Tr> <TD>

        </TD nowrap> timeislifetimeis lifetimeis lifeareyousure </tr>

        </Table>

      3. Example3:

        <Style type = "text/CSS">

        . Tableautowrap1

        {

        Table-layout: fixed;

        }

         

        </Style>

         

        <Body>

         

        <Table class = "tableautowrap1" width = "100">

        <Tr> <TD>

        </TD nowrap width = "50%"> timeislife timeis lifetimeis lifeareyousure <TD> </tr>

        </Table>

    2. Firefox: Table-layout: Fixed + nowrap (optional) + Div

      So far, there is no good solution for fixfox, the only workaround is to hide the overflowed text, andTD'S width must use percentage instead of absolute width.

      For example:

      <Style>

      . Tableautowrap {table-layout: Fixed}

      . TD1 {overflow: hidden ;}

      </Style>

       

      <Table class = "tableautowrap" width = 80>

      <Tr> <TD width = 25% class = "TD1" nowrap>

      <Div> ttimeislifetimeislifet imeislifeimeislife </div>

      </TD>

      <TD class = "TD1" nowrap> <div> ttimeislifetimeislifet imeislifeimeislife </div> </TD>

      </Tr>

      </Table>

       

      Note: All the foregoing solution will only be word-wrap (line-wrap) at the blank of a string of long characters, if you want to make the word-wrap occurs at every position where the length of the characters exceed the line width, you can use the following CSS element:

      <Style type = "text/CSS">

      . Textarea1

      {

      Overflow: hidden;

      }

      </Style>

       

<Textarea class = "textarea1" Cols = "10" rows = "4"> ccccccccccccccccccccccccccccc </textarea>

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.