Friday, May 19, 2006

Use the pre tag when displaying inline code snippets

The pre tag preserves formmatting and does not eliminate white space (unlike the other tags which do eliminate whitespace). This is important when displaying inline code snippets so that code indenting is preserved.

Another little note is that when using the div tag, CSS margins and padding is not preserved. I probably just don't understand HTML. Anyway, here are some examples:

Using div:
void foo ()
{
int a = -1
return a;
}


Using pre:
void foo ()
{
int a = -1
return a;
}


Notice that when I use pre my indentation and margines are preserved, while they are discarded when using div.

3 Comments:

Blogger Xira said...

I'm just commenting becasue I love your name. I've been waiting my whole life to meet someone named Hans. Cool blog.

12:24 PM  
Blogger Xira said...

I'm just commenting becasue I love your name. I've been waiting my whole life to meet someone named Hans. Cool blog.

12:24 PM  
Blogger Xira said...

I'm sorry that I left two copies of my previous comment...I don't know how it ended up that way.

12:24 PM  

Post a Comment

<< Home