Some css selector has # in front of it, what does that mean?
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 id
s in your page just like named anchors, and I gather that it's why CSS uses the same notation for selecting IDs.
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>
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>
In CSS,
#
is Mention for ID Selector
.
is Mention for Class Selector
You might also have seen something like
div#myDiv {}
Which means "a DIV-tag with ID set to 'myDiv'"