Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In HTML, how can I wrap a word at . (dot), just like it wraps at - (dash)?

Tags:

html

css

I have a long word in a table cell that messes up the table layout:

a.long.word.separated.by.dots

I would like the word to wrap like this word:

a-long-word-separated-by-dashes

How can I get this done, with CSS, without changing the HTML?

like image 482
Simon Avatar asked Oct 25 '25 00:10

Simon


2 Answers

If using JS is okay, you can do this. If it is not, then this answer may still be useful for future readers.

var longWord = "a.long.word.separated.by.dots".replace(/\./g, '.<wbr>');

Reference on the wbr tag: http://www.w3.org/wiki/HTML/Elements/wbr

Alternatively, you could put a <wbr> after each period manually.

like image 62
11684 Avatar answered Oct 26 '25 16:10

11684


You can do it in PHP, sorry for waking a dead question, but if you're populating an HTML table using a PHP loop you just need something like:

preg_replace('/\./', '.<wbr>', $string);

This takes 11684's answer and puts it into the requested context.

like image 23
Milhouse Avatar answered Oct 26 '25 15:10

Milhouse



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!