Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make HTML layout whitespace-agnostic?

Tags:

html

css

EDIT: There is the almost same question at Removing whitespace between HTML elements when using line breaks , however apart from "float" suggestion I find none of the answers suitable for my requirements. I'd like this to stay open for more innovative suggestions

If you have consecutive inline-blocks white-space becomes significant. It adds some level of space between elements. What's the "correct" way of avoiding whitespace effect to HTML layout if you want those blocks to look stuck to each other?

Example:

<span>a</span>
<span>b</span>

This renders differently than:

<span>a</span><span>b</span>

because of the space inbetween. I want whitespace-effect to go away without compromising HTML source code layout. I want my HTML templates to stay clean and well-indented.

I think these options are ugly:

1) Tweaking text-indent, margin, padding etc. (Because it would be dependent on font-size, default white-space width etc)

2) Putting everything on a single line, next to each other.

3) Zero font-size. That would require overriding font-size in blocks, which would otherwise be inherited.

4) Possible document-wide solutions. I want the solution to stay local for a certain block of HTML.

Any ideas, any obvious points which I'm missing?

like image 778
Sedat Kapanoglu Avatar asked Apr 07 '10 21:04

Sedat Kapanoglu


1 Answers

You shouldn't use the version with no space in between elements, just make everything work with space. You'll probably need to set inline elements to display:block to achieve the correct layout.

Have a look at this similar question of mine, which has some good answers.

Edit: One of the answers on the above question suggests using HTML comments as a last resort, e.g.:

<span>a</span><!--
--><span>b</span>
like image 116
Skilldrick Avatar answered Sep 19 '22 21:09

Skilldrick