views:

99

answers:

5

Some css selector has # in front of it, what does that mean?

+11  A: 

It's the ID selector, a fundamental part of the CSS language. It matches the HTML element with the given id. See W3Schools for more.

<!DOCTYPE html>
<html lang="en">

<head>
  <style type="text/css">
  #my-div {
      color: #f00;
  }
  </style>
</head>

<body>
  <div id="my-div">This text will be red.</div>
  <div id="another-div">This text will not be red.</div>
</body>

</html>

You may also have seen the # notation used to refer to named anchors (<a name="some-anchor"></a>) using <a href="#some-anchor">anchor links</a> to get around a page. These can also point to certain ids in your page just like named anchors, and I gather that it's why CSS uses the same notation for selecting IDs.

BoltClock
+1  A: 

It selects based on the id of html element...

http://www.w3.org/TR/CSS2/selector.html#id-selectors

<style>
#myDiv { }
</style>

<div id="myDiv">
</div>
jayrdub
+2  A: 

The selector, #foo will match any element with an ID attribute with a value of "foo".

<style type='text/css'>
#foo { color: red; }
</style>

<div id='foo'>red text</div>
Mark Cidade
+1  A: 

In CSS,

# is Mention for ID Selector

. is Mention for Class Selector

Karthik
"Normally"? What are the exceptions?
RPM1984
+1  A: 

You might also have seen something like

div#myDiv {}

Which means "a DIV-tag with ID set to 'myDiv'"

sewa