Visual Semantics

In response to Mark Pilgrim’sPushing the envelope” post, Hans Nowak complains that sometimes semantically correct HTML elements don’t “look good”. So, he tends to use <pre> instead of <code> to designate code fragments in web pages.

The answer, of course, is to just use CSS to make <code> act more like <pre>. Here’s my CSS:


code {
white-space: pre;
}

And here’s how it renders Hans’ code fragment:


def f(x, y):
if x > y:
print "foo!"
else:
print "bar!"

Stumble It!
Visual Semantics

Related posts:

  1. Upgraded
    " I’ve upgraded this site to WordPress 1.2. The process was quick and painless. It took me about 20 minutes, 15 of which was spent..."
  2. XSLT-Fu
    " I’ve recently started learning XSLT. The basics aren’t too hard, but as usual, I’ve been trying to move faster than I can absorb things...."
  3. Beyond Time and Space
    " Many years ago, a friend of mine showed me a book called The Tao of Programming. The koans contained within struck a chord with..."
  4. WordPress 1.2 “Mingus”
    " Yesterday, Matt released WordPress 1.2 (nicknamed “Mingus”). The whole team put a lot of effort into this release. And I’m also proud that WP..."
This entry was posted in Uncategorized and tagged , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

3 Comments

  1. Posted December 27, 2002 at 8:39 pm | Permalink

    This is how I’d do it too. I’m told IE doesn’t support CSS’s white-space tho. I wouldn’t know for a fact, since I never need to use IE. Mozilla & Opera work better and handle more coding capabilities . Hmmm….maybe this is a good reason to start slapping “works best in Mozilla” or “Viewed best in Opera” phrases/images on websites. I remember when the web used to be filled with “Best viewed in Netscape” images.

  2. Posted December 28, 2002 at 7:36 am | Permalink

    I can vouch that it works fine in IE 5.5 and 6.0. I suspect that it IE 5.0 also understands “white-space:pre”, but I don’t know about 4.0.

  3. Posted December 29, 2002 at 5:56 pm | Permalink

    What’s wrong with using


    <pre><code>
    var x = z - y++;
    </code></pre>?

    You don’t have to worry about support for white-space: pre; then, and it’ll work in all browsers that can do <pre>

Post a Comment

Your email is never published nor shared.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Subscribe without commenting