Overflow code

When I put code in my posts, I try to keep the length of the lines short enough to fit within the width of the content area of the blog. But sometimes, like in this recent post, I mess up and the lines are still too long to fit. I’ve noticed that some sites have a neat horizontal scroll bar on their overly-wide code blocks, so I hunted down the CSS that provides that feature. It’s

overflow: auto;

which I’ve just added to this blog’s CSS entry for pre. Now I can have

really really really really really really really really really really really really really really really really long lines

and readers will still be able to read the whole thing. I don’t want to abuse this new-found power—it’s still much easier to read code without scrolling—but it’s nice to have a way to make sure that I show all the code even when I can’t get the line breaks right.

Tags: