Suggest a Snippet Login Register
  • LOG IN:

    Not a member? JOIN NOW!
     Username                   Password
    Remember me Recover password
DevSnippets Design Community & Snippets Gallery
  • Subscribe by RSS
>
  • Webdesign
    • Design
    • HTML5
    • lists
    • Menu
    • Navigation
    • Portfolio
    • Showcase
    • Template
    • Tooltip
    • Tutorial
    • webdesign
  • Web development
    • AJAX
    • CodeIgniter
    • CSS
    • CSS3
    • Database
    • Javascript
    • jQuery
    • Mootools
    • MySQL
    • PHP
    • PHP Framework
    • plugins
    • WordPress
    • WordPress Hacks
  • Inspiration
    • Fonts
    • Icons
    • Inspiration
    • Mac
    • Mac apps
    • Photography
    • Wallpapers
  • Snippets
In {CSS Techniques/ Techniques} -5th May-

How to use comments in Css

You know the story, you start to code, you start to add comments, but soon enough you get so sucked into it that you start to neglect adding more. We are all guilty of it once and a while. So what can we do about it?

How can we make our code more manageable?
Use Comments for better readability

Again when cluttered in between a lot of code, comments soon become well hidden little notes. You can help to combat this by making them stand out a little better.
Example

/* Using spaces at both ends punctuates the comment */

Rather than keeping important comments to a single line, try to add some white space around them;
Example

/*
This is a little better, isn’t it?
*/

You can also jazz up larger blocks with more “/” if you want to, but try to use this for the more important headers, or sections of your code.
Example

/*/////////////////////////////////

Look how important this comment is!

/////////////////////////////////*/

You might want to use these large blocks at the start of your Css file to add your details, such as your name, or link to your blog.
Use Comments as headers

One of the things you can do to start, is to separate your code into sections, quite often before I start to coding up a stylesheet, I start by adding several header comments.

These can be anything you want them to be but try not to make them too complicated. Instead of writing “This is the styling for the all the headers” Just use “Header Styling” as your comment heading. That way when scanning the code you can get a better idea of what each section is about.
Example
Main Header

/*/////////////////////////////////

MAIN CONTENT Styling

/////////////////////////////////*/

Secondary Header

/* MAIN CONTENT Typography Styling */

Element Header

/* Link Styling */

Use Comments for explainations

Its all well using comments to separate sections, but its also important to include any reasons as to why you added an element or rule. Why did you add that extra pixel to the padding? What is the reason behind that float: left; rule?
Example

#wrapper {
margin: 0 auto; /* this is to auto center the wrapper */
position:relative;
}

Of course you don’t have to do this for every element, be selective, did that rule solve a problem? Maybe you can use it again in another project?

This will also help to re-enforce some vital Css techniques, and allow you to remember them easier.
Use comments to plan ahead

Using comments to plan ahead of time, or to remember important aspects can greatly improve your chances of getting everything done.

Although it’s important to keep your comments relevant to you code, you can use them to add notes to it.

Using comments to plan ahead of time, or to remember important aspects can greatly improve your chances of getting everything done.

I like to add a section at the top of my Css stylesheets where I can add anything that comes to mind, this doesn’t necessarily have to be related to the Css itself.

I have often added new ideas or to do lists!

Direct Link →
Paul Mackenzie

Category: CSS Techniques, Techniques

No Comments, Add Comment or Ping


This comment thread is closed. If you want to share any information, please contact us.

  • Tabs (28)
  • Forms (133)
  • Menu (64)
  • Tables (9)
  • Navigation (36)
  • ToolTips (23)
  • LightBox (41)
  • Calendar (9)
  • AutoComplete (13)
  • Accordion (15)
  • Sliders (40)
  • Gallery (84)
  • Image Effects (62)
  • Date & Time (16)
  • Charts (16)
  • Carousel (12)
  • Tag Clouds (1)
  • Links (1)
  • Layouts (83)
  • IE Hacks (19)
  • Image Sprites (7)
  • Sliding Door (7)
  • Techniques (84)
  • Image Effects (17)
  • Font Styles (22)
  • Positioning (5)
  • Menus (43)
  • Rounded Corner (20)
  • Tools (1)
  • Drop Shadows (1)
  • CSSFrameworks (2)
  • Mootools (85)
  • jQuery (344)
  • Prototype (23)
  • Scriptaculous (10)
  • Javascript (126)
  • javascript Framework (1)

Sponsored Ads

ADVERTISE HERE

Sponsored Ads

Code & Design Snippets

Jun/22/2010
How to Style Individual Wordpress Posts...
Matt
WordPress
Jun/22/2010
50 Must Have HQ Typography Wallpapers
lava360 blog
Jun/21/2010
Tutorial: Wordpress 3.0 Custom Post...
Jared Thompson
WordPress
Jun/19/2010
How to Create a Redirect Page Template...
Eko Setiawan
WordPress
Jun/17/2010
Become a WordPress Expert with these...
Dennis
Jun/13/2010
Everything a Web Designer Should Know...
Webanddesigners
Jun/13/2010
Building a live news blogging system in...
webia
Jun/13/2010
5 Reasons Gravity Forms Makes Your Form...
Matt
WordPress
Jun/13/2010
Free Plugin : DynamicWP Image Cube
Eko Setiawan
WordPress
Jun/13/2010
Free Wordpress Themes Green Eco Design
templates4all
WordPress
Jun/13/2010
Simple CSS3 Dropdown Menu
hdytsgt
Jun/07/2010
10 Resources to Help You Create a...
Matt
WordPress
Jun/06/2010
Animated Navigation Menu with CSS3
vikas ghodke
Jun/06/2010
FIFA 2010 WordPress Theme
Vinay
WordPress
Jun/06/2010
CSS font size: Is relative sizing still...
Chet
More Code Snippets →

Design Community News

  • Is It Worth Shifting To Photoshop CS5?

    SloDive
    Jul/04/2010
  • Free Wordpress Theme Vector Nature Template

    templates4all
    Jul/04/2010
  • Best jQuery plugins – June 2010

    Spider8411
    Jun/22/2010
  • Freebies: Vintage Mega Pack 10 Samples from Designious.com

    Doink
    Jun/22/2010
  • CSS3 Animations, the Power Back to CSS Part 1: Transitions

    Teylor Feliz
    Jun/22/2010
  • Create a Photo-Realistic Candle with Basic Photoshop Tools

    Frank
    Jun/22/2010
  • Credit cards and payment icon set

    icon sets
    Jun/22/2010
  • 40 Refreshing Nature Inspired Web Designs

    Brukhar
    Jun/22/2010
  • How to Create a Tumblr Theme (Code Structure)

    Dainis Graveris
    Jun/21/2010
  • The Simple Photoshop CS5 Cheat Sheet

    Frank
    Jun/21/2010
More News →

Our Friends

  • Graphic Design School

  • MoreTechTips

  • Designm.ag

Top ↑

Add a Snippet / Design News

© 2008-2010 DEVSNIPPETS | Made by Noura Yehia | Submit Snippet | About| Subscribe | Advertise
In partnership with (mt) Media Temple