Home arrow Style Sheets arrow Adding Text Indentation to Style Code Blocks with CSS
STYLE SHEETS

Adding Text Indentation to Style Code Blocks with CSS


In this concluding article to a seven-part series on styling code blocks with CSS, I'll show you how to finish the example we've been working with by adding predefined indentation to make the code more readable.

Author Info:
By: Alejandro Gervasio
Rating: 5 stars5 stars5 stars5 stars5 stars / 1
April 06, 2010
TABLE OF CONTENTS:
  1. · Adding Text Indentation to Style Code Blocks with CSS
  2. · Review: styling online code blocks using ordered lists
  3. · Adding indentation to code lines with custom CSS classes
  4. · Including the CSS styles in a web page

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Adding Text Indentation to Style Code Blocks with CSS
(Page 1 of 4 )

When it comes to defining the visual presentation of web pages with CSS, the task isn’t limited to building eye-catching headers and footers, decorating paragraphs, or converting arid and boring lists into stylish navigation bars. In reality, when coupled with the proper HTML tags, style sheets can be a powerful tool that permits you to give online code blocks a polished and readable look, without having to deal directly with the complexities of full-featured server-side or JavaScript-based code formatters/highlighters.

To demonstrate how useful CSS can be for styling code snippets included in (X)HTML documents, in some articles previous to this one I developed a decent number of examples which used a combination of <pre> and <code> tags and ordered lists to easily improve the visual appearance of a sample PHP fragment. While the combination composed of <pre> and <code> elements is by far the simplest way to decorate online code fragments, ordered lists can produce even more professional results. They allow you to generate line numbers automatically, because that’s an ordered list's default behavior.

What’s more, in the last installment of the series I showed how to apply an engaging zebra effect and a gutter to an online code fragment whose structure rested on an ordered list. This process only required us to create a single background image. In summary, does this mean that we’ve finished styling code blocks with CSS? Not so fast! Style sheets can also be used for adding proper indentation to the lines of those code blocks, quite similar to what you can achieve automatically with <pre> tags.

So, in this last article of the series I’ll be adding the final touches to the example created in the previous tutorial, by giving the sample PHP snippet a predefined indentation. As you'll soon see, this indentation can be customized with minor tweaks.

Ready to tackle the final part of this hopefully educational journey? Then let’s get going!


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 2 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials