Tutorials

Latest Word » Tutorials » CSS Beginners Do’s and Dont’s Part 2
CSS Beginners Do’s and Dont’s Part 2

CSS Beginners Do’s and Dont’s Part 2

Tags:

This is the second part to my previous article “CSS Beginners Do’s and Dont’s Part 1“, if you haven’t checked it out yet now is a good time. In part one, I went over general tips and reminders, in this article I would like to go over more of the technical aspects of CSS.

1. DO use Class/IDs Appropriately (Don’t whore your Class/IDs!)

Beginners typically have the tendency to create a new class or ID for every element on a page. When you end up packing your stylesheet/markup with redundant and unnecessary class/IDs, you start to defeat the purpose of CSS. The beauty of CSS is that it allows you to separate design from markup, so lets keep the class/ID overload to a minimum!

BAD Example

<div id="sidenav" class="left">
    <p class="side-heading"><strong class="green">Side Navigation Title</strong></p>
    <p class="sidenav-menu1"><a href="#" class="blue-link">Home</a></p>
    <p class="sidenav-menu2"><a href="#" class="blue-link">About</a></p>
    <p class="sidenav-menu3"><a href="#" class="blue-link">Services</a></p>
    <p class="sidenav-menu4"><a href="#" class="blue-link">Portfolio</a></p>
    <p class="sidenav-menu5"><a href="#" class="blue-link">Contact</a></p>
</div>

Good Example

<div id="sidenav">
    <h2>Side Navigation Title</h2>
    <ul>
        <li><a href="#">Home</a></li>
        <li><a href="#">About</a></li>
        <li><a href="#">Services</a></li>
        <li><a href="#">Portfolio</a></li>
        <li><a href="#">Contact</a></li>
    </ul>
</div>

2. DO Keep Your Styles Clean and in Your Stylesheet

I’m sure most of us do this from time to time (I’m guilty of this too!), but don’t leave inline styles on your markup. It’s a sloppy habit and it creates potential inconsistency in the long run. As beginners its very important to get in good habits by taking all styles off of your markup and neatly organize them into your stylesheet.

Bad Example

<h1 style="font-size: 20em; font-weight: normal; font-family: arial; color: red; padding: 10px; margin: 10px;">H1 - Heading</h1>

Good Example
HTML

<h1>H1 - Heading</h1>

CSS

/*------Global Heading Properties------*/
h1 {
    font: 20em normal arial;
    color: red;
    padding: 10px;
    margin: 10px;
}

3. DO Learn Tricks and Limit Hacks

There are a lot of tricks out there that can fix cross-browser issues without using any hacks. Do learn to use these instead of hacking up your stylesheet. Below are some great resources to learn tricks you should get very familiar with.
Helpful CSS Resources

4. DO Optimize Your CSS

There are various ways you can optimize your CSS. Check out my previous article
5 Step CSS Weight Loss Program” to get some ideas and tips on what you can do to avoid stylesheet bloating.

5. DO Learn How to Use Absolute Positioning Properly

I sometimes run into sites where every element on the page is using an absolute positioning. Absolute positioning is powerful and useful but should not be abused in this way. Do learn the correct methods of creating layouts using a combination of floats and block elements, don’t abuse absolute positioning!

Helpful Articles Elsewhere

Related Posts

Author Bio

My name is Soh Tanaka and I am a Los Angeles based designer/front-end developer specializing in CSS driven web design with an emphasis on usability and search engine optimization. I also run a CSS Gallery which is updated daily with the best CSS websites from around the world. Come check it out!

You can learn more about me or Twitter  Follow me on twitter for more updates and resources!

Did You Enjoy This Post?

subscribe  Subscribe via RSS or by email to get all upcoming tutorials and articles delivered straight to you.

+ Add Comment28 Peeps Have Spoken Their Minds...

  1. Paul

    Nice post. It certainly helps to start learn css the right way.

  2. Elena

    Both of these articles have been especially helpful. CSS is very valuable once the concepts are understood. Thanks for the tips.

  3. hagin

    Its helpful, ths for share

  4. Chris Coyier

    Yeah I think that absolute positioning one is a biggie. I find beginners often pick up the opinion somewhere that it is bad to use it, and thus never really understand it’s proper use. I find as I’ve matured as a designer I use it A LOT.

  5. Steve

    Both articles good like beef noodle!

  6. z0r

    Learn alot and work more not to suck at CSS – that’s what it is about.

  7. web design st louis

    Yeah. I wish I had a resource like this when I was first starting.

  8. Neil

    This article kept with lots of good and relevant information. This is a good resource for the newcomer to get lots of information from here.Keep up the good work.

  9. Christoph

    very good advices. too bad, that there weren’t such posts 6 or 7 years ago :)

  10. Ares Vista

    CSS changed the web design industry in such a dramatic way. Yet you still see people not really using it to its full potential. It’s a tool, sure. But it’s also a mindset, a way of designing.

  11. Yigit Ozdamar

    Great post again! I think you should write more article like that. Thanks a lot!

  12. jT.

    I’m a newbie with CSS looking to learn. Very helpful. Thanks!

  13. Cheap Websites - Josh

    Very informative post. I need to clean up my CSS a bit I think! By the way, your blog has great CSS design. One of my favorites out there. Thanks.

  14. Web Development Company

    Tanks. Its helpful for beginners.good advoice.

  15. Josh Stauffer

    This is some good information that I, too, wish was around when I was learning. Thanks!

  16. Newbie CSS Guy

    Nice information post and it is too helpful for beginner learner of CSS.

    Thank you

  17. mike

    i would add:

    6. DON’T use !important unless you really really have to. then, still don’t.
    7. DO learn how cascading and specificity work. if you make a selector too specific, you won’t be able to override it without using !important.
    8. DON’T use !important.

  18. Web Design Company

    Awesome tips!! Really helps out beginners…

  19. Ant

    Sometimes it’s needed to add classes for navigation elements, because they use different images. But if you may drop legacy browsers, you may use :nth-of-child(n) instead.

  20. Jaycee

    Great!! :) i love this site. :D

  21. Budi Kurniawan

    Great reference for my learning of CSS.

  22. CSSFRESHBLEND.COM

    Nice beginner tut!

  23. Web Guru

    A good read for me. Really helpful resources and links.

  24. Kristaps Lazda

    Yeah, sometimes even I know it`s not correct I tend to do it anyway. Need to work on correct css more!
    @Mike Also with the !important.. sometimes it`s just get`s frustrating and then it`s the only thing which works. Probably it`s just laziness to find a proper way :D
    Thanks for the tips! :)

  25. Toronto Web Developer

    Great tips. #2 made me laugh, because I do that…from time to time.

  26. exmmedia

    nice css tips bro, we have a lot of css to figure out and now even the css3 hopefully not that bad apart

  27. Xcellence IT

    Nice tips… thanks

  28. ANOOP

    Really helpful. Thanks a lot :)

Speak Your Mind...

Post HTMLNeed to Post HTML Code? Use Postable to post code friendly html. *Wrap all html code in <pre></pre> tags.
Post HTMLNeed to Keep Updated with Comments? Subscribe to comments now.

CSS Gallery