Question

I have a div tag that contains an URL inside. After some external format ends up with come line breaks (carriage return, line feed) that are interpreted as white space in the HTML*. Something like

yaCRLR hoo.com

and in the html preview shows:

ya hoo.com

Do anyone have an idea how to force to avoid this line break Thanks in advance for any insight you may have.

Was it helpful?

Solution

If the HTML document contains line break in element content, as in

<div>
ya
hoo.com
</div>

as you seem to be saying, then you cannot prevent the line break as being taken as whitespace, in HTML or CSS. You can affect (in CSS) the way whitespace is handled (e.g., whether line breaks cause line breaks in rendering or just inter-word space), but this does not include the “ignore it” option.

Well, there is a tricky and risky way of setting word-spacing to some negative value that is expected to cancel the effect of spaces.

<div style="word-spacing: -0.25em">
ya
hoo.com
</div>

The typical width of a space is about 0.25em, but it varies by font. And this would affect (“neutralize”) all whitespace in the element.

It is easy to remove line breaks with JavaScript, once you have specified which line breaks are to be removed from where. But it is better to modify the process that generates the HTML document in the first place.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top