We are the pioneers and the web is our ocean.

CSS Tips For The Day

This past week has been a bit of a learning experience and although the items learned are small, they are worthy gems to be added to my vast CSS arsenal.

  1. CSS id’s and classes can not begin with a numeric character, otherwise they won’t even be recognized. I learned this the hard way.
  2. If you define the charset in your stylesheet (@charset "UTF-8";), nothing can come before it. I discovered that most browsers are a bit lax with this (Firefox) and will give you a pass. Safari, on the other hand, is strict and will give you some issues.

I found that if you place the charset in your stylesheet below a comment, Safari would completely ignore some of your CSS declarations. The problem I was running into was that the CMS we are using automatically places an opening and closing comment at the top and bottom of each stylesheet you create on the back end. This is done because the stylesheets are stored in the database and this is how it sees the start and end to each stylesheet.

On the older versions of CMS Made Simple, if you attached more than one stylesheet to a template, the system would automatically render them all in one stylesheet but it would have a start and end comment for each stylesheet. Although the newer release renders each stylesheet individually now, the start and end comments still exist – thus giving me the charset issue.

Being an avid Coda user, I never define the charset at the top of my stylesheet. I’ve never seen it as a diehard requirement and I’ve never encountered any problems leaving it out. My colleague is an avid Dreamweaver fan and if you’re familiar with Dreamweaver, it automatically adds @charset "UTF-8"; to the top of any stylesheet you create.

Similar Posts

  • No Related Post

4 Responses to “CSS Tips For The Day”

  1. Daryn says:

    I think it’s a good practice to define your charset. I agree with you on leaving it out altogether in this situation though.

  2. [...] Read the original here: CSS Tips For The Day [...]

  3. No worries. :) BTW, I’ll pass this on to the DW team. Though the charset is part of the specs, there’s really no issue with removing it altogether. In this case, it’s the best solution. Ciao!
    @stefsull

  4. Daryn says:

    Also, special thanks to @stefsull for helping me work these out. I don’t know how I overlooked the first one. I just never tried it and never read it anywhere.

Leave a Reply

Allowed tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>