Style Sheets
  Home arrow Style Sheets arrow Using Ordered Lists to Style Code Blocks w...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
STYLE SHEETS

Using Ordered Lists to Style Code Blocks with CSS
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2010-03-31

    Table of Contents:
  • Using Ordered Lists to Style Code Blocks with CSS
  • Review: using pre and code tags with online code blocks
  • Building enumerated online code fragments with ordered HTML lists
  • Assigning a base style to code snippets

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Using Ordered Lists to Style Code Blocks with CSS


    (Page 1 of 4 )

    In this fourth part of a seven-part series on styling code blocks with CSS, I explain how to enhance the visual presentation of code blocks on web pages by using something as simple as an ordered HTML list. This approach permits you to automatically generate line numbers, which makes code fragments much more readable.

    As with many other things that comprise the vast terrain of professional web design, there are different approaches one can take to give code blocks included in web pages a more polished and readable look. From using server-side syntax formatters, to appealing to the functionality of JavaScript-based highlighters, there are numerous options that permit you to improve the visual presentation of online code snippets.

    While the aforementioned solutions can best be implemented where it’s necessary to display code fragments that span a great variety of languages and technologies, a simple combination of CSS styles and some common HTML tags can produce remarkable results as well. This is especially true when it comes to preserving only the format of the code blocks, and highlighting their syntax is optional.

    To demonstrate how simple it is to enhance the look and readability of the blocks in question with style sheets, in previous part of this series I developed a bunch of easy-to-follow examples. They used some common CSS properties, along with the tandem comprised of the <pre> and <code> HTML tags, to preserve the format and appearance of a sample PHP snippet while leaving its semantic meaning untouched. By far, this method is the most used nowadays due to its flat learning curve and easy implementation.

    As I said a moment ago, however, the combination of <pre> and <code> elements isn’t the only way to polish the visual presentation of online code blocks. There are a few other approaches that don’t use <pre> tags and can produce even better results. For the sake of brevity, in this case I plan to cover only one of those alternative methods. It relies on ordered lists to enumerate lines in code fragments, similar to the typical feature found in code editors and IDEs.

    So, in the lines to come I’ll be showing you how to use ordered HTML lists to turn a boring and unreadable web page code fragment into an engaging and elegant code container, worth looking at over and over again.

    Ready to learn the fine details of this “make up” process? Then jump ahead and start reading!

    More Style Sheets Articles
    More By Alejandro Gervasio


       · This fourth part of the series demonstrates how to enhance the visual presentation...
     

    STYLE SHEETS ARTICLES

    - Styling HTML Lists with CSS: Manipulating Pa...
    - Styling HTML Lists with CSS: Specifying Pad...
    - Styling HTML Lists with CSS: Resetting Paddi...
    - Absolute Positioning in CSS: a Dynamic Menu
    - CSS Absolute Positioning: Creating a Quick S...
    - CSS: Building Tooltips with Absolute Positio...
    - Styling Pseudo Classes with the RGBA CSS3 Pr...
    - Controlling Overall Transparency of an HTML ...
    - Altering the Border Opacity of an HTML Eleme...
    - The RGBA CSS3 Property: an Overview
    - Using Span Tags to Include Logos in Web Pages
    - Using a Single H1 Element to Include Logos i...
    - Combining Divs and H1 Elements to Include Lo...
    - Semantically Including Logos in Web Pages
    - Adding Text Indentation to Style Code Blocks...





     


     


    © 2003-2010 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek