Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Whitesapce question 1

Status
Not open for further replies.

Crisps

Programmer
Sep 28, 2006
26
US
Is it possible to completely ignore white space in html?

for example I would like to display button1 and button2 next to each other with no gap. It would be nice if I could make my code readable as follows

Code:
<div id="top_bar">
  <img src="button1.jpg"/>
  <img src="button2.jpg/>
<div/>

instead of

Code:
<div id="top_bar">
<img src="button1.jpg"/><img  src="button2.jpg/>
<div/>

is there perhaps a tag I can wrap around them to make the whitespace be ignored?

Obviously this is a simple example, but you can see the readability issue when there are 20 buttons each with lots of attributes.

Thanks



 
Nope. Between inline elements white space will always be taken into account. The only way you could do what you want is by transforming those buttons to blocks and then float them.

___________________________________________________________
[small]Do something about world cancer today: PACT[/small]
 
You could be sneaky like this:
Code:
<div id="top_bar">
  <img src="button1.jpg"/><
   img src="button2.jpg/>
<div/>
as whitespace inside tags is ignored.

Or you could use CSS to make the images float left instead of being inline.

-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
Cheers, I'll go with the sneaky approach. Really just ttrying to make some large html documents readable code, the sneaky method should be good enough.
 
Why not use [tt][maroon]float: left[/maroon][/tt] on all IMGs?

- Lowet

[gray]Why can't all browsers parse pages the same way? It should be the Web designer who decides how to display the content, not the browser![/gray]
 
ChrisHunt said:
Or you could use CSS to make the images float left instead of being inline.
Lowet said:
Why not use float: left on all IMGs?
That has already been suggested above.


-------------------------------------------------------

Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Delivering professional ASP.NET solutions
[URL unfurl="true"]http://weblogs.asp.net/marksmith[/url]
 
How about:
Vragabond said:
The only way you could do what you want is by transforming those buttons to blocks and then float them.
ChrisHunt said:
Or you could use CSS to make the images float left instead of being inline.
Lowet said:
Why not use float: left on all IMGs?
I guess it is getting more and more specific :)

___________________________________________________________
[small]Do something about world cancer today: PACT[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top