specific order for selectors/properties in CSS doc?

topic posted Thu, July 26, 2007 - 10:14 AM by  Ms.Dynomite
Share/Save/Bookmark
Advertisement
(cross-post)

I've searched and can't find this info. Is there a specific order that should be used for selectors, or for properties within selectors to create a proper, clean document? For example, I've read that in order for text rollovers to work the selectors must appear in the following order: link, visited, hover, active.

but what about other elements?

Does it matter if you write....

color: #715A53;
font-family: Verdana, Arial, Geneva, Helvetica;
font-size: 19px;
line-height: 24px;
font-weight: bold;

...as opposed to reordering them:

font-weight: bold;
font-family: Verdana, Arial, Geneva, Helvetica;
line-height: 24px;
font-size: 19px;
color: #715A53;


Does it matter if you write...

background-color: #D6CCC4;
padding-top: 20;
padding-right: 10;
padding-bottom: 30;
padding-left: 20;
color: #53504d;
font-family: Arial, Verdana, Geneva, Helvetica;
font-size: 9px;
line-height: 13px;
font-weight: bold;
text-align: left;

...putting the background and padding first, as opposed to:

color: #53504d;
font-family: Arial, Verdana, Geneva, Helvetica;
font-size: 9px;
line-height: 13px;
font-weight: bold;
text-align: left;
background-color: #D6CCC4;
padding-top: 20;
padding-right: 10;
padding-bottom: 30;
padding-left: 20;

...which does the opposite?
Advertisement
Advertisement
  • I think when you write "position: absolute" you have to put the "left" and "top" things right after. But actually, if there's only one of those properties, then the browser can parse them in any order.

    The order of stuff after the selector is a matter of your coding style, and I don't think there's a standard.

    Personally, I like to talk about the box model first, then the fonts.
    From outside to inside
    From parent to child
    From top of the page to bottom

    So within a selector, it would go something like:
    postiion
    width, height
    border
    margin, padding
    background
    font-family
    font-size
    font-weight
    font-style
    text-transform
    tex-decoration

    But my recent documents are a little sloppy in that respect.

    In short hand, the two or three or four sizes that you write after the colon have an order. I'm not sure if there's a strict order for "border: 1px solid #fff;" or if you can write "border: dashed #4f4 2px;"

    BTW, on that note, I found out that the only thing you need to make a border happen is "solid" or "dashed" or whatever. The rest can be built from defaults, which are "3px" and the color of the text inherited.

    border: solid;

    "link, visited, hover, active" is important for old IE, or maybe for strict parsing, but all the browsers I tried can come up with a policy given the slightest information. I just say "a" for normal, and then "a:hover" for rollover. But I guess I need to clean that up.

    I'm caring less about IE, as long as the content is visible. I'm not stressing out if one of my fancy effects doesn't function in a browser that can't even smooth the fonts.


    So is that it? Anybody got any better info?
    • thanks, that's helpful. :)
      my tendency is to work as you've suggested (outside-inside, parent-child, top-bottom).
      with margins & padding I list Top, Right, Bottom, Left since that matches the shorthand order. I've always seen border listed in order of width, style, color so I haven't deviated from that. Any other shorthand rules you know of?

      and yeah, I wish they'd just abolish IE off the planet. it's useless and annoying. I'm baffled that anyone still uses it, but according to The Counter it's far more used than FireFox. it's sad.
      • Re: IE

        07/26
        "I'm baffled that anyone still uses it"

        Simple: between 1997 and 2007, they handed out brand new Windoze computers to people who formerly couldn't get their VCR's to stop blinking "12:00." These people had a brand new copy of XP, with a 5-yr old browser. For the first time in history, we had a popular piece of software with no revisions for like 5 years.

        So, back to the VCR people: "Download? I'll ask my daughter about it, but my system administrator says no." The only way the majority of users could even be aware of alternative browsers would be if Explorer were set to open up Mozilla.org on startup--and then auto-install.

        On my QA machine, where I have 98 running on Virtual PC on a G4, my explorer 6 automatically logs in to Microsoft homepage. Here they tell you to upgrade to version 7. Then you click on the download button, and you find out that version 7 won't run on 98.
        • Re: IE

          07/27
          true. sad, but true. ;) my heartless estimation is that these people deserve their browsers. and the companies who insist on keeping them deserve all the security breaches and bugs hat come with it. ;)

          and yeah, I've encountered the same thing with IE/MS. I keep a range of browsers, new to old, for testing on my Mac. The last IE made for mac is IE5, which is so outdated that even Yahoo Mail can't work on it. I don't have the option to download IE 6 or 7. I have to go to the PC machine for that.

          MS is evil in it's blandness and mass. ;)
          • Re: IE

            07/28
            Again, anybody running IE5 Mac deserves it. Even when you go to the MS website for Mac, they tell you to "run Safari, Dummy."

            I remember when the slogan was "Microsoft's best browser runs on Mac." And it was true. IE 5 Mac surpassed IE 6 Win. It was much closer to the standards and it even rendered 24-bit transparency for PNG.

            But here's one cool thing that you can only do on Explorer: you can pair a CSS doc with a standalone XML. Watch what happens. It's as if you never needed to use HTML again and you could just add a style to any XML tag you could think up. K-Z !

Recent topics in "CSS is not a disease!"