使用 css 修剪字符串

Bij*_*u s 2 css

我想使用 css 修剪字符串。例如我的字符串是

“嗨,谷歌,你好吗”

我想获得输出

“你好”

得到前两个字母。使用 Css 是否可以修剪字符串。

Khe*_*dey 8

虽然不可能使用 CSS;但是您可以在理想状态下获得某种错觉,这可能是适合您的解决方法。我在这里使用过,text-overflow: ellipsis; 您可以查看DEMO

<p>hi google how are you</p>

p {
    text-overflow: ellipsis;   /* IE, Safari (WebKit) */
    overflow:hidden;              /* don't show excess chars */
    white-space:nowrap;           /* force single line */
    width: 17px;  /*This property playing a major role just showing the first 2 letter*/
}
Run Code Online (Sandbox Code Playgroud)