Home » Web

The style of pre tag I like

By: Zhiqiang Ma On: Jan 28, 2010 Views: 8 Comment: 1 Print Email
Tags: , ,

I use <pre> tag a lot in the html. I believe the guys that usually past codes into the pages will like it too.

I use the pre tag to list programming code such as C/C++, php, Linux shell output and some other content that is suitable for Monospace font.

The effect is what it is here. It has a scroll bar and it has a solid frame which will make it clear.

The style of pre tag I like most is this one:

pre {
    border: 1px dashed #888;
    padding: 5px 10px;
    margin: 0 0 1em 0;
    overflow: auto;
}

/* no vertical scrollbars for standards-compliant browsers */
/* no vertical scrollbars for IE 7 */
*:first-child+html pre:hover {
    padding-bottom: 20px;
    overflow-y: hidden;
    overflow: visible;
    overflow-x: auto;
}
/* no vertical scrollbars for IE 6 */
* html pre:hover {
    padding-bottom: 20px;
    overflow: visible;
    overflow-x: auto;
}

Update history:
Updated on May 26, 2010. Scroll bar appear only when hover

Read more:

Digg del.icio.us Stumble Techorati Facebook Newsvine Reddit Twitter
Mixx LinkedIn Google Bookmark Yahoo Bookmark MySpace LiveJournal Blogger RSS feed
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

One Comment »

  • Eric said:

    The dashed version:

    pre { border:1px dashed #333; padding:5px 10px; margin:0 0 1em 0; overflow:auto; }

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

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

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.