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 Style the Portfolio

Marc-Adems Dor
Marc-Adems Dor
2,854 Points

Random question

I dont know if me asking this will make any sense. But what is the difference wen selecting an item in our code, for exemple, selecting the body just like that or selecting the gallery by adding the hashtag or pound symbole in front (#) for what purpouse do we had the hashtag (#) when selecting an item?

here is 2 different exemple:

gallery li {

float: left; width: 45%; margin: 2.5%; background-color: #f5f5f5; }

body { background-color: #fff; color: #999;

}

Tanks!

3 Answers

Hello Marc-Adems, the # symbol is used to select IDs whereas body is simply selecting the body element. Here's a resource for further explanation, and below you could select the ul (unordered list) element, or #gallery, for this demonstration.

        <ul id="gallery"> <!-- This is the gallery ID -->
          <li>
            <a href="img/numbers-01.jpg">
              <img src="img/numbers-01.jpg" alt="">
              <p>Experimentation with color and texture.</p>
            </a>
          </li>

P.S. Hashtags are also used in front of hexadecimal colors.

Kevin Korte
Kevin Korte
28,149 Points

When you are selecting an element, there are no hashtag's or periods before it. There are lots of elements you can call. Any of these would be valid. There are a lot more.

body { };
input { };
article { };

These are elements, like inputs, articles etc.

When you use a hashtag, you are selecting elements that have an ID of that value.

So #gallery li would select some sort of element, with an ID attribute of gallery. And .gallery li would select some sort element with a class attribute of gallery.

<ul id="gallery">
  <li>List item</li>
</ul>

<div class="gallery">
  <article>
    <p>My article</p>
  </article>
</div>

See how each of those selectors would interact with the above HTML?

Marc-Adems Dor
Marc-Adems Dor
2,854 Points

Thanks a lot both of you it actually helps out a lot