How do you wrap long words on newline, and avoid horizontal scroll using CSS?

前端 未结 3 544
南笙
南笙 2021-01-11 17:17

I have the folowing html:

long text here

and css:

.box {
    width: 400px;
    h         


        
相关标签:
3条回答
  • 2021-01-11 17:41
    word-wrap: break-word
    

    https://developer.mozilla.org/en/CSS/word-wrap

    0 讨论(0)
  • 2021-01-11 17:58

    The solution I have used in the past is an ellipsis library like http://dotdotdot.frebsite.nl/ for jquery, you can specify the number of chars and have it dot dot dot after that so it all fits on one line.

    0 讨论(0)
  • 2021-01-11 18:03

    For custom word breaking, there is an html special character that is not so often used- ­ (soft hyphen) - that will split words on 2 lines and insert a dash after the first part of the word if the word approaches the edge of its container. Trouble is, you'll have to place them everywhere you want them. As you say, though, you can also set up a js or php function, and insert them into the appropriate places.

    0 讨论(0)
提交回复
热议问题