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

Html web design css trouble

I don't know if I missed something but on my website, I want to have the function that allows me to hover over my 3 sections(Portfolio, About, Contact) and display a different font color. I would appreciate if you could write the code that activates this function (I am almost sure it's part of css). If there is any confusion, please describe what you are not understanding, and I would be happy to explain.

4 Answers

Hey there, Kanav.

I'm still learning myself...so I'm not going to write the code out for you (why steer you in a wrong direction?), but what you are describing is almost certainly a transition effect, which I think you will be able to discover for yourself in this library offering: CSS: Beyond the Basics

Best of luck.

Hi Kanav, Check out the CSS :hover selector

Happy coding! Brenna

Hello Kanav,

This is a simple hover effect you're talking about which can easily be done using CSS. You first set the color of the font you're working with (if you don't set it, it will just be black). Then you set a hover state on that same element and put a different font color. This can also be used to change just about anything on an element. An example would look like this:

section {
    color: blue; /* This sets the font color to blue */
}

section:hover {
    color: red; /* This changes the font color to red, while hovering over the entire section */
}

You can check out the links from the previous 2 posters and experiment to get a more in-depth knowledge of the hover state.

Hi Kanav,

If you have 3 sections with an HTML structure like:

<div id="portfolio" class="section">Portfolio</div>
<div id="about" class="section">About</div>
<div id="contact" class="section">Contact</div>

And you would like the text color to be different for each section you hover on, you would apply style like this:

.section {
  color: white;
}
#portfolio:hover {
  color: red;
}
#about:hover {
  color: green;
}
#contact:hover {
  color: blue;
}

I hope this answers your question!