Why doesn't break word work on a long string with commas?

前端 未结 3 1342
广开言路
广开言路 2020-12-17 17:13

I have a long comma delimited string and I\'m trying to use the css style word-wrap:break word but it doesn\'t seem to work on a string without spaces. Is this expected?

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-17 17:51

    I plused one Michael's answer for his workaround.

    However, I've tested the word-wrap property on a few browsers (recent versions of safari, ff, chrome) and it does seem to be stable already (I've just read that it works too on the latest IE versions). What's seems to disturb the thing in your example Paul, is using it inside a table-cell (and anything with display: table-cell). In a div (with display: block), for example, it works perfectly fine.

    Take a look at this fiddle. Mess around with it and you'll realize the same thing: http://jsfiddle.net/joplomacedo/DQmJB/

    Edit:
    I've just found this has been already answered on a fairly popular question here on this site. The problem does come from it being used inside a table. The workaround suggested there is to set the table-layout to fixed and giving the table element a specific width: http://jsfiddle.net/joplomacedo/DQmJB/3/

    If you're ok with adding a width to your table, then this might be a good way to do it.

提交回复
热议问题