Style Sheets
  Home arrow Style Sheets arrow Using a Zebra Background Effect to Style C...
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 a Zebra Background Effect 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-30

    Table of Contents:
  • Using a Zebra Background Effect to Style Code Blocks with CSS
  • Review: adding an elegant and readable look to online code fragments
  • Enhancing code snippet readability with a zebra background effect
  • Displaying the zebra background on screen

  • 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 a Zebra Background Effect to Style Code Blocks with CSS


    (Page 1 of 4 )

    In this third part of a seven-part series on styling code blocks, I demonstrate how to add an engaging zebra background effect to a PHP fragment included in a web page. This background effect improves its readability. As you'll see, the process is very similar to assigning background images to other HTML elements, so you shouldn’t have major trouble implementing this effect in your own website.

    Have you ever wanted to empower your technical-minded blog with tons of carefully-crafted code snippets, but you still don’t know how to make them look attractive and readable to your demanding visitors? Fortunately, the solution to your problem is much easier to implement than you might think. Best of all, it requires you to have only an average background in (X)HTML and CSS.

    A simple combination of style sheets and HTML tags can be the perfect recipe to provide your online code blocks with an elegant appearance that will please your loyal users, without having to appeal to the functionality offered by complex server-side and JavaScript-based syntax highlighters.

    Naturally, just saying how simple it is to polish the visual presentation of code fragments on web pages with CSS needs to be backed up with a bunch of demonstrative and functional examples. In previous articles of the series I demonstrated how to style a short PHP fragment embedded in an (X)HTML document by using a couple of <pre> and <code> tags, in conjunction with a few basic CSS properties.

    This process not only turned the PHP fragment into a piece of appealing and readable code, but its inclusion was semantically reflected in the document, thanks to the correct utilization of <code> elements. Also, while this CSS-based approach will work remarkably well with most online code snippets, it can be enhanced even further with the incorporation of the so-called “zebra background” effect. This effect assigns different colors to odd and even lines of code.

    Adding this little decorative touch is very easy with CSS, so in the lines to come I’ll be explaining how to implement it within the sample web page defined in the previous chapter of the series.

    Are you ready to learn how to add a cool “zebra effect” to your code snippets? Then start reading right now!

    More Style Sheets Articles
    More By Alejandro Gervasio


       · This third part of the series on styling code blocks demonstrates how to add a...
     

    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 10 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek