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); |