8

#test is the selector for id="test"

.test is the selector for class="test"

but how do you remember which way round they are (eg not .=id)

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
servermanfail
  • 2,532
  • 20
  • 21
  • 10
    It's one of the most commonly used bits of CSS. You can learn through repetition. I don't need a mnemonic. – Quentin Feb 20 '11 at 18:48
  • 8
    The same way how you remember that 2 comes after 1, and 3 comes after 2, etc. ... or that the past form of "do" is "did", ... – Šime Vidas Feb 20 '11 at 18:52
  • 2
    What these guys said. If you need a gimmick to remember this basic CSS syntax, you're probably not going to get very far in the software world. Sorry. – Lightness Races in Orbit Feb 20 '11 at 18:56
  • 2
    (In all seriousness, though, think of "Platform #3" or "Book #19" .. there's only one. It's an identifier, or "id".) – Lightness Races in Orbit Feb 20 '11 at 18:57
  • 5
    I'm pleased for you all that you can remember something. I wasn't asking for personal attacks, just a mnemonic. I don't spend enough time a year with CSS (thank god) to warrant committing this to my long-term memory. Finite capacity, and all. – servermanfail Feb 22 '11 at 08:39
  • I wouldn't worry about your memory having a finite capacity. While that might be true in theory, you have a *long* way to go before you reach it. (And I don't mean that to imply you're stupid; that's true of anyone! I learn all kinds of new things every day, and I'm nowhere near capacity.) – Cody Gray - on strike Feb 22 '11 at 08:48
  • 2
    servermanfail, odds are a mnemonic is going to be longer and harder to remember that "dot class, pound id". – Dave Child Feb 22 '11 at 09:20

6 Answers6

12

Well, in truth these things are so common that most people don't need mnemonics to remember them, but here's something I came up with, if it helps:

In terms of a filename a . and then an extension denotes a type of thing. There can be many different things of this type. With CSS, using classes you can denote a single style for many elements of the same type.

In terms of a URL, a # denotes an anchor link to a specific spot in the document. It refers to one location only. With CSS, using IDs you denote a single style for a single specific element.

Matt
  • 385
  • 1
  • 5
6

If a police officer catches you with "hash," he will ask to see your ID. If not you get to stay classy. It's really dumb, but that's how I remember.

Ben Gartner
  • 14,413
  • 10
  • 36
  • 34
5
  • CallerID shows a phone #.
  • Periods are round like pearls, and-- Pearls are classy.

(P.S.: What's with all the "you learn differently than me, so you suck" comments? Goodness. Repetition is OK for me, but if I can visualize something I pick things up more quickly. In fact, the weirder something is the easier it is to memorize!)

JemWritesCode
  • 502
  • 6
  • 17
2

I learned it the same way I learned that quotes (rather than parentheses) are used for attributes' values — by typing them a couple of times.

If you or someone you know gets tripped up by # vs ., though, consider that many programming languages use a . to access the members of an class-typed object.

ClosureCowboy
  • 20,825
  • 13
  • 57
  • 71
  • Of course! *smacks head* I was stuck thinking that # was a channel - like a Twitter hash tag (goes to a group), or an IRC channel (group of people). – servermanfail Feb 22 '11 at 08:43
1

I see I'm a day late (and maybe a dollar short), but I had the same problem in the early days and the following helped: for the dot (.) as the selector for Class, I remembered it as: "My class always starts on the dot, not a minute early or late." for the number sign (#) for ID, I just reminded myself that an ID(entification) card is incomplete without its number.

Vijay
  • 11
  • 1
0

Spend lots of time writing CSS. When you've got it wrong enough times, your brain will give in and retain it.

Dave Child
  • 7,573
  • 2
  • 25
  • 37
  • Thanks, would you like to pay me for spending lots of time writing CSS, as I do not enjoy it and limit myself in terms of minutes per year. – servermanfail Feb 22 '11 at 08:43