Css/js text overflow automatically add ellipses ellipsis

Source: Internet
Author: User
Tags strlen xmlns

CSS text overflow ellipsis

Text-overflow:ellipsis

Ext-overflow is a special attribute that is in the previous document (the current document does not contain the Text-overflow attribute, fml!) The definition of this is:

Name:text-overflow-mode

Value:clip | ellipsis | Ellipsis-word

Clip: does not show ellipsis (...), but rather simple trimming

Ellipsis: An ellipsis (...) is displayed when text overflows inside an object, and the caret insertion position is the last character.

Ellipsis-word: Displays an ellipsis (...) when text overflows inside an object, and the position where the ellipsis is inserted is the last word (word).

Example

The code is as follows

. ellipsis li{

-moz-binding:url (' ellipsis.xml#ellipsis ');/* relative to current HTML path * *

Overflow:hidden;

Text-overflow:ellipsis;

White-space:nowrap;

width:200px;

}

You may also have noticed that the key code-moz-binding:url (' Ellipsis.xml#ellipsis ') compatible with the Firefox browser; is to load an XML file.

Ellipsis.xml Code:

  code is as follows &nbs P;

<?xml version= "1.0" encoding= "Utf-8"

<bindings

 xmlns= "HTTP://WWW.MOZILLA.ORG/XBL"

 xmlns:xbl= "HTTP://WWW.MOZILLA.ORG/XBL"

  Xmlns:xul= "Http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"

    <binding id= "ellipsis"

        <content>

             <xul:description crop= "End" xbl:inherits= "value= Xbl:text

                <children/>

            </xul:description

        </content>

    </binding>

</bindings>

To ask me why, these are browser bugs and I don't want to delve into

Download this jquery plugin: jquery ellipsis plugin

Call Method:

The code is as follows

$ (document). Ready (function () {
$ ('. Ellipsis '). ellipsis ();
}

Direct character interception in PHP

  code is as follows &nbs P;

public static function Chinesesubstr ($str, $start, $len) {//$str Refers to the string, $start the starting position of the string, $len the string length
        $strlen = $start + $len; Strlen The total length of the stored string, from the starting position of the string to the total length of the string
        for ($i = $start; $i < $strlen;) {
            if (Ord (substr ($str, $i, 1)) > 0xa0) {/ /If the first byte in the string has an ASCII value greater than 0xa0, the kanji
                 $tmpstr. = substr ($str, $i, 2); Each time you remove the two-bit word assignments to the variable $tmpstr, that equals a Chinese character
                 $i = $i +2; Variable add 2
           } else{
                $tmpstr. = substr ($str, $i, 1) ; If it is not Chinese characters, each time you remove one character assignments to the variable $tmpstr
                 $i + +;
           }
       }
        return $tmpstr;//back String
   }

Use method

Chinesesubstr ($str, 0);

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.