Formatting code or commands on your blog with CSS

I have spent quite a bit of time figuring out how to make this blog easier to read visually. One thing I came up with is CSS to make the commands or code that I describe easier to pick out and easier to see due to formatting.

Here’s the CSS I used for the

 tag.  This will allow nicely formatted pre sections with your code or commands.  I opted to wrap the words for really long lines instead of using the horiztonal scroller.

I’ve tested this on Mac OS X with Opera, Safari, Chrome, and Firefox and it works great.

I like the added effect of the background and rounded corners as well.

pre {
color: white;
overflow-Y: hidden;
overflow: auto;
font-family: “Consolas”,monospace;
font-size: 9pt;
text-align:left;
background-color: black;
overflow-x: auto; /* Use horizontal scroller if needed; for Firefox 2, not needed in Firefox 3 */
white-space: pre-wrap; /* css-3 */
white-space: -moz-pre-wrap !important; /* Mozilla, since 1999 */
white-space: -pre-wrap; /* Opera 4-6 */
white-space: -o-pre-wrap; /* Opera 7 */
word-wrap: break-word; /* Internet Explorer 5.5+ */
_white-space: pre; /* IE only hack to re-specify in addition to word-wrap */
margin: 0px 0px 0px 0px;
padding:6px 5px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
-khtml-border-radius: 5px;
border-radius: 5px;
}

3 Responses to “Formatting code or commands on your blog with CSS”

  • The BEST way I found to format ANY code is
    http://quickhighlighter.com/
    They know tons of languages and you can have it with and without line numbers. Highly recommended.
    :-) stw

  • david says:

    Wow, what a powerful site.

    Here’s the re-formatting of the above with quick highlighter. Hopefully, it works.

    1. pre {
    2. color: white;
    3. overflow-Y: hidden;
    4. overflow: auto;
    5. font-family: “Consolas”,monospace;
    6. font-size: 9pt;
    7. text-align:left;
    8. background-color: black;
    9. overflow-x: auto; /* Use horizontal scroller if needed; for Firefox 2, not needed in Firefox 3 */
    10. white-space: pre-wrap; /* css-3 */
    11. white-space: -moz-pre-wrap !important; /* Mozilla, since 1999 */
    12. white-space: -pre-wrap; /* Opera 4-6 */
    13. white-space: -o-pre-wrap; /* Opera 7 */
    14. word-wrap: break-word; /* Internet Explorer 5.5+ */
    15. _white-space: pre; /* IE only hack to re-specify in addition to word-wrap */
    16. margin: 0px 0px 0px 0px;
    17. padding:6px 5px;
    18. -moz-border-radius: 5px;
    19. -webkit-border-radius: 5px;
    20. -khtml-border-radius: 5px;
    21. border-radius: 5px;
    22. }
    23.  
  • david says:

    So it sort of worked with a direct copy/paste of both the CSS and the HTML.

    I could have edited out the line numbers and it would have looked better, but I wanted to see if it was a simple, no-brainer procedure.

    Thanks for the tip, it will come in useful.

Leave a Reply

Consulting

I'm currently available
for Lotus Notes / Domino consulting engagements.

LinkedIn

Connect with me:

LinkedIn

Advertisement
Advertisement
Categories