Home arrow Style Sheets arrow Decorating Line Numbers in Code Blocks Styled with CSS
STYLE SHEETS

Decorating Line Numbers in Code Blocks Styled with CSS


In this penultimate part of the series, I demonstrate how easy it is to add a gutter and a zebra background effect to an online code fragment by using a single background image. You can edit and modify the image to suit your own requirements. The possibilities are endless.

Author Info:
By: Alejandro Gervasio
Rating: 5 stars5 stars5 stars5 stars5 stars / 1
April 05, 2010
TABLE OF CONTENTS:
  1. · Decorating Line Numbers in Code Blocks Styled with CSS
  2. · Review: using an ordered HTML list
  3. · Adding a gutter and a zebra background to the sample code fragment
  4. · Final touches: displaying the gutter and the zebra background

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Decorating Line Numbers in Code Blocks Styled with CSS
(Page 1 of 4 )

Improving the visual presentation of code blocks on web pages is a process that can be tackled via different approaches. These may range from using server-side applications, usually written in PHP, Python or Ruby, to working directly with JavaScript-based syntax highlighters. However, it’s possible to get similar results by means of a simple combination of CSS and a few common HTML tags, without having to deal with the complexities of a full-featured code formatter/highlighter program.

To demonstrate the veracity of my statement, in previous chapters of this series I showed how to provide online code snippets with an elegant and polished look, first by using a couple of <pre> and <code> elements, and then with something as trivial as an ordered list. This last method is particularly useful, since it permits you to automatically generate line numbers while maintaining the semantic meaning of the snippet intact.

What’s more, in the last installment I started illustrating how to decorate a sample PHP fragment included in a web page by using an ordered list along with some <code> tags. I have to say, however, that in its current state, this example looks somewhat rough and unfinished. It's only capable of displaying the aforementioned line numbers and highlighting code lines, which offers nothing particularly interesting. Obviously, this implies that it’s necessary to introduce some additional enhancements that make the PHP snippet look even more attractive and stylish.

With that premise in mind, in the lines to come I’ll be adding a tiled background image to the pertinent code fragment. This image will create a neat gutter and an engaging zebra effect. This will be a straightforward process, take my word for it. So click on the link below to learn a few more useful things about styling code blocks with CSS!


blog comments powered by Disqus
STYLE SHEETS ARTICLES

- CSS Combinators: Working with Child Combinat...
- CSS Combinators: Using General Siblings
- Intro to CSS Combinators
- CSS Semicircles and Web Page Headers
- Drawing Circular Shapes with CSS3 and Border...
- More CSS Pagination Link Templates
- CSS Pagination Links
- Animated CSS3 Image Gallery: Advanced Transi...
- CSS3 Animated Image Gallery: Transitions
- CSS3 Properties: Fixed Heights with box-sizi...
- CSS3 Properties: Altering Strokes and 3D Eff...
- CSS3 Properties: Text-Stroke
- CSS3 Transitions: Width and Height Properties
- Creating a Drop Down Menu in CSS3
- Intro to CSS Transitions

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 8 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials