Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS How to Make a Website Styling Web Pages and Navigation Polish the Navigation and Footer

in css when do you need to use the # when you are trying to identify an element in your html?

ive noticed that, for instance if you give an id to a wrapper or a gallery, you need to use # when selecting that in css.

is it only when you have created such an element?

also, are there instances where you have more than one wrapper, and how would you tell css the difference between the two when selecting?

3 Answers

Stephen Printup
seal-mask
.a{fill-rule:evenodd;}techdegree
Stephen Printup
UX Design Techdegree Student 45,252 Points

Hey Brandt-

It sounds like you are discovering the difference between class selectors and ID selectors. More information can be found here: http://www.w3schools.com/css/css_selectors.asp, but basically ID selectors are for single instances (say a single gallery you would like to target on your site i.e. 'wedding picture gallery' on a page full of galleries). The hash id selector can be used with more elements than just divs and galleries. The class selector looks similar but can target several elements at once based on 'scope,' or in other words, where your objects fall in the DOM (document object model) tree.

Also, a wrapper is a div named wrapper. You can have more than one div, but if you rename it wrapper you may run into trouble. We put the sites objects in a div (named wrapper) to contain them within the body so we can easily style all the content at once using CSS.

-Stephen

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

Hello Bradt.

You can use an ID with any element so if you give an ID attribute to an element it's selected by using # so the selector becomes an ID selector.

p id = "bold"></b>
p#bold {
    font-weight: bold;
}

Be aware though that once you use a particilar ID on one element you won't be able to use it on another. :-) Hope this helps

Vittorio Somaschini
Vittorio Somaschini
33,371 Points

Hello Brandt.

#

means you are selecting according to the id of the element, and you are the one that sets the id of one element when creating the html (writing for example:

<div id="one"></div>.

So since the id has to be unique, you will get that specific element only when selecting it.

If you want to select multiple elements using only one css selector, you should probably opt for using a class in the html, and this can be the same for more than one element.

;)

Vittorio