How do I only display part of a string using css

前端 未结 7 1913
梦谈多话
梦谈多话 2021-02-05 19:01

I want to be able to display a string of characters up to 10 characters. If the string goes over 10 characters, I\'d like to append \'...\' to the end.

For example, if

7条回答
  •  清酒与你
    2021-02-05 19:47

    The best way is using:

    text-overflow: ellipsis;
    

    in your css

    This will restrict your text to the width of the container. If the text exceeds the width, it will instead be displayed with an ellipsis (...).

    This may help: https://www.w3schools.com/cssref/tryit.asp?filename=trycss3_text-overflow

提交回复
热议问题