DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Author Topic: HTML line break spacing  (Read 5,210 times)

flib

  • Participant
  • Joined in 2009
  • *
  • Posts: 9
HTML line break spacing
« on: November 09, 2011, 07:31 AM »
I'm having a really dumb issue and I've just about exhausted my ability to search for an answer.
Here's a basic example of the problem. It really seems like there ought to be some way to fix this with CSS:
Code
<p>Hello w
orld</p>
Outputs
Code
Hello w orld
Rather than
Code
Hello world

This happens because there is a linebreak between 'w' and 'world'. This is mostly an issue because this also happens with images and I would rather that it didn't.

Renegade

  • Tell me something you don't know...
  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 13,291
    • Participated in NANY Challenge Three Times
    • Furry Fandom Badge - Furry Fandom
    • Linux User
Re: HTML line break spacing
« Reply #1 on: November 09, 2011, 09:18 AM »
It would be wrong to fix that with CSS. Line breaks serve 2 purposes: 1) Content, 2) Code Formatting. So, there's no way to determine whether the line break is one or the other there. As such, it's interpreted as a space in those cases.

e.g.

Code: (html4strict)
<p> This is
a paragraph. And it has 
2 sentences.
</p>
<pre>But this is preformatted
text
and
displays 
as
you see it here.</pre>

I'm not sure if my spaces at the ends of the lines will be rendered here. (Most lines have no spaces.)

Try using a text editor that doesn't automatically break lines. That should solve the problem.
Slow Down Music - Where I commit thought crimes...

Freedom is the right to be wrong, not the right to do wrong. - John Diefenbaker

Renegade

  • Tell me something you don't know...
  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 13,291
    • Participated in NANY Challenge Three Times
    • Furry Fandom Badge - Furry Fandom
    • Linux User
Re: HTML line break spacing
« Reply #2 on: November 09, 2011, 09:21 AM »
Also, have a read here:

http://stackoverflow.com/questions/1097006/removing-whitespace-between-html-elements-when-using-line-breaks

That addresses the image issue, though all the solutions are messy.

And check here for the authority:

http://www.w3.org/TR/html4/struct/text.html#line-breaks

Slow Down Music - Where I commit thought crimes...

Freedom is the right to be wrong, not the right to do wrong. - John Diefenbaker

flib

  • Participant
  • Joined in 2009
  • *
  • Posts: 9
Re: HTML line break spacing
« Reply #3 on: November 09, 2011, 01:17 PM »
Thanks, float:left; fixed it.

Original address: https://www.donationcoder.com/forum/index.php?topic=28623.0