views:

37

answers:

2

When using Ruby on Rails or other framework, a lot of time we generate <span> or <img> in a loop, and each line will be on a new line.

So when it is rendered in HTML, there will be extra space between those inline elements.

How can it be solved? Must they be made into 1 long line, or solvable using HTML or CSS?

+2  A: 

The whitespace is treated as a space character by the browser resulting in the gap. You could:

1) render it onto 1 long line with no gaps between the elements; or 2) apply float: left to the elements so they sit flush up against each other

Matty F
1) how to make it one long line? have to set a tmp variable and concat the strings? It is clumsy using HAML too... 2) hm... wanted to use span in the first place because floating div cause another problem in IE 7. (with max-width)
動靜能量
I'm not sure how those platforms render HTML, did Neall's answer below help at all?
Matty F
+1  A: 

If you're using HAML, you probably want to use < and > to control whitespace:

HAML Docs on Whitespace Removal

Neall