Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

HTML Introduction to HTML and CSS Getting Familiar with HTML and CSS Building Web Pages with HTML and CSS

CSS class calling

***** HTML ****

      <img src="images/me.png" alt="Drawing of Jane Smith" class="profile-image">
      <h1 class="tag name">Hello, I'm Michael.</h1>
      <p class="tag location">My home is Sagay, Negros Occidental.</p>

***** CSS *****

header .profile-image {
  margin-top: 50px;
  width: 150px;
  height: 150px;
  border-radius: 50%;
  border: 3px solid white;
  transition: all .5s;
header .profile-image:hover {
  transform: scale(1.2) rotate(5deg);
.tag {
  background-color: #e2e2e2;
  color: black;
  padding: 10px;
  border-radius: 5px;
  display: table;
  margin: 10px auto;

In this example (.tag) class is under the header as well, but why is there no header in front when calling in CSS? The (.profile-image) is called with a header. What is the difference?

1 Answer

Rohald van Merode
Rohald van Merode
Treehouse Staff

Great question Carl Michael Libo-on!

In this example it would work either way. Main purpose of adding the header element to the selector is that you'll ensure that only .profile-image elements that are nested inside the header will get the styling applied to it. If you would have a different section on the page that also has a .profile-image element this element won't have the same styles applied to it. If you however would remove the header from your selector it will be applied to all the elements on the page with the profile-image-class.

Hope this clears things up 🙂

Now it makes sense to me. Thanks :)