473,387 Members | 1,882 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Gaps caused by whitespace: solutions without changing HTML code?

When one encounters mysterious gaps between elements, like:

<div>
<img src="one.gif">
<img src="two.gif">
</div>

it's typically because the browser renders whitespace in the code as
text. (Like a space character.) The usual solution offered is to remove
any whitespace in the code, like this:

<div
<img src="one.gif"
<img src="two.gif"
</div>


or like this:

<div><!--
--><img src="one.gif"><!--
--><img src="two.gif"><!--
--></div>

Ick! Is there a more elegant workaround that doesn't involve modifying
the HTML? Perhaps some CSS? Font-size has no effect whatsoever on the
gap. I couldn't find anything except the code-related solutions above.

Thanks for your help.

May 19 '06 #1
4 3252
bl**@blaqzone.com wrote:
When one encounters mysterious gaps between elements, like:

<div>
<img src="one.gif">
<img src="two.gif">
</div>

it's typically because the browser renders whitespace in the code as
text. (Like a space character.) The usual solution offered is to remove
any whitespace in the code, like this:

<div
><img src="one.gif"
><img src="two.gif"
></div>


or like this:

<div><!--
--><img src="one.gif"><!--
--><img src="two.gif"><!--
--></div>


Or this:

<div><img src="one.gif"><img src="two.gif"></div>
May 19 '06 #2
bl**@blaqzone.com <bl**@blaqzone.com> scripsit:
When one encounters mysterious gaps between elements, like:

<div>
<img src="one.gif">
<img src="two.gif">
</div>

it's typically because the browser renders whitespace in the code as
text. (Like a space character.)
You might put it that way. Anyway, you have real space characters between
the <img> elements, too. By the way, why do you use invalid markup, without
alt attributes? (To write sketchy code, <img> would be sufficient, so the
odds are that you really intend to omit alt attributes.)
The usual solution offered is to
remove any whitespace in the code, like this:

<div
><img src="one.gif"
><img src="two.gif"
></div>

Well, maybe. Or simply just
<div><img ...><img ...></div>
or like this:

<div><!--
--><img src="one.gif"><!--
--><img src="two.gif"><!--
--></div>

Ick!
Ick indeed. Comments considered harmful (in HTML). People just shoot
themselves on the foot with them.
Is there a more elegant workaround that doesn't involve modifying
the HTML?
No. You are not supposed to be able to remove character data (including
spaces) from HTML documents without actually removing it.
Perhaps some CSS?
You could play with positioning. But why are you trying to avoid the most
obvious and simplest solution, inventing possible workarounds that just
might work on sunny days (when CSS is on)?
Font-size has no effect whatsoever on the gap.


It has. Try setting font-size:60px to see the difference.

May 19 '06 #3
blaq wrote:
Ick! Is there a more elegant workaround that doesn't involve modifying
the HTML? Perhaps some CSS?


You might be able to use letter-spacing in CSS, but the better solution is
to remove the white space in your code.

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact

May 22 '06 #4

bl**@blaqzone.com wrote:
it's typically because the browser renders whitespace in the code as
text. Is there a more elegant workaround


Learn where the whitespace is significant. It's not a problem around
block elements, it's the inlines that are affected by it -- which
isn't altogether unreasonable.

May 22 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Mark247 | last post by:
Hi, When transforming an XSLT to HTML I get a very annnoying white spac gap of about 2px under each image. This is particularly annoying as am creating a vertical navigation menu made up of images...
4
by: Justin Archie | last post by:
Alright, this newsgroup is my last hope. I have tried many solutions to my problem, but none of them seem to work. I have been wroking on this site layout at...
5
by: cool2005 | last post by:
I have a table contains 4 cells (2 x 2) like this http://www.coolshare.com/planttrade/temp/gap.jpg each cell contains a div and the div contains a table. As you can see from the image above,...
5
by: Arno R | last post by:
I need to find the 'gaps' in a numbered recordset like: 1 Philips 2 Jones 5 Jo Do 6 Frenzy 10 John Matthias 23 Arno R (and so on ....) What I need is one...
20
by: ilyas | last post by:
I have some html which consists of a paragraph tag and some text inside it What I want to do is to maintain the whitespace in this paragrpah so that it appears exactly like that in the browser,...
3
by: e271828 | last post by:
I'm trying to access the source of an HTML page with as few alterations from the actual source (as in, that seen from the View Source option) as I can. The method...
4
by: Shug | last post by:
Hi, We're reformatting a lot of our project code using the excellent uncrustify beautifier. However, to gain confidence that it really is only changing whitespace (forget { } issues for just...
1
by: mark r | last post by:
Trying to create a page like popurls displaying rss feeds from music sites only im trying with one to start from NME.com and the output errors with the message "Whitespace is not allowed at this...
1
by: Michal Kwiatkowski | last post by:
Hi, I'm working on Pythoscope, a unit test generator for Python and stumbled into the following problem. I need a way to analyze and modify Python AST tree, but without loosing source code...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.