Style Sheets
  Home arrow Style Sheets arrow Styling Code blocks with CSS: Using pre HT...
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

Styling Code blocks with CSS: Using pre HTML Tags
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2010-03-11

    Table of Contents:
  • Styling Code blocks with CSS: Using pre HTML Tags
  • Styling code blocks: a starting web page
  • Formatting with the pre HTML tag
  • Assigning a basic style to the pre tags

  • 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


    Styling Code blocks with CSS: Using pre HTML Tags


    (Page 1 of 4 )

    In this first part of a series you will learn how to improve the look and readability of code snippets in web pages, thanks to the use of something as simple as a pair of <pre> tags and some CSS styles. This approach does a decent job of styling online code blocks.

    Introduction

    Unquestionably, polishing the visual presentation of code blocks on web pages is one of those tasks that you, as a web designer, will have to face sooner or later. Be it when developing a website for a client that must provide a bunch of code samples to their content-hungry visitors, or even when building your own blog, it’s very probable that at some stage of the process you’ll need to define the look and feel of code snippets.

    A good example of this is the Developer Shed network, which is made up of several websites whose contents usually include a variety of code fragments that need to be presented to the reader in an elegant, readable fashion. Obviously, the list goes on and on.

    To be frank, there are several approaches that can be used to give online code snippets a more appealing appearance without having to sacrifice their readability, which range from using server-side and JavaScript-based highlighters, to working with methods that rely purely on CSS. While the former methods are definitively best suited for use on websites that display code fragments covering different languages and technologies, the latter are by far much easier to implement, as they only require an average background in style sheets and (X)HTML. It’s that simple, really.

    Considering that this topic is indeed interesting and even fun (well, that’s only my personal opinion), in this article series I’m going to discuss how to use a basic combination of CSS and some simple HTML tags to make your online code blocks look more professional and readable, and best of all, without having to mess up your web pages with ugly and non-semantic markup.

    Does my proposal sound good enough for you? Then don’t waste more time; start reading right now!

    More Style Sheets Articles
    More By Alejandro Gervasio


       · Styling online code blocks with CSS is a very simple process, as long as you use...
     

    STYLE SHEETS ARTICLES

    - 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...
    - Decorating Line Numbers in Code Blocks Style...
    - Changing the Color of Code Lines with CSS
    - Using Ordered Lists to Style Code Blocks wit...
    - Using a Zebra Background Effect to Style Cod...
    - Displaying Rounded Corners Built with CSS3 i...
    - Building Rounded Corners with CSS3`s -webkit...







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