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 trialLearning coding
Front End Web Development Techdegree Student 9,937 PointsHow do I change the text of the navbar when I hover over it?
This is the code I tried wich doesn't work:
nav.navbar-nav li a:hover { color: #3FBF50; }
This is my workspace. https://w.trhou.se/xauywzcaf7. Who can help me with the right code?
7 Answers
Redweb FED
15,517 PointsFor you workspace you appear to be looking for the class nav rather than the tag.
Your code has this: " .nav.navbar-nav. li a:hover "
You should write it like so: " nav.navbar-nav. li a:hover "
Hope this helps
Learning coding
Front End Web Development Techdegree Student 9,937 PointsNo problem and thanks for reacting, but when I target with #, or (.) it get's ignored. Can you take a look at my code that I posted before? (Can't take any snapshots anymore)
Redweb FED
15,517 PointsSure thing I made a codepen and messed around with it till I got a result I assume you were expecting.
http://codepen.io/Adam_Rusty/pen/GroXXQ?editors=1100
Turns out that using .nav.navbar-nav is fine. the main issue was having a "." at the end of .nav.navber-nav once I removed it the hover worked fine.
nav.navbar-nav. <--- This dot here.
Learning coding
Front End Web Development Techdegree Student 9,937 PointsThis is the code in your codepen the text in the buttons get green.
.nav.navbar-nav li a:hover { color: #3FBF50; }
In my css the code seems to get ignored, because the text doesn't become green.
Redweb FED
15,517 PointsTry copying my code underneath yours and see if you can find the difference. Its had to tell what the problem is your end so hopefully you can spot whats going on.
Learning coding
Front End Web Development Techdegree Student 9,937 PointsOk, so this is your code:
.nav.navbar-nav li a:hover { color: #3FBF50; }
My code: .nav.navbar-nav li a:hover { color: #3FBF50; }
It's the same code. I don't understand this, you copy pasted the exact codes from my workspace right?
Redweb FED
15,517 PointsYeah I did, I also commented above the change I made to you code as well.
Did it resolve the problem?
Learning coding
Front End Web Development Techdegree Student 9,937 PointsYes, I copied the code wich you have changed, but the problem is not resolved yet. It's exactly the same code as above.
Learning coding
Front End Web Development Techdegree Student 9,937 PointsAm i missing something? This is my recent code btw https://w.trhou.se/ld9nmxc3v2 Thanks for so far!
Redweb FED
15,517 PointsI've got good news and bad news the good news it the css is being applied the bad news is its being overruled by what I assume is some bootstrap styling.
To resolve this you can use this:
.nav.navbar-nav li a:hover { color: #3FBF50 !important; }
This effectively tells the browser to apply these styles above all others relating to that property in this case color being overwritten. the only expection to this is if you give a more specific selector the "!important" value as well.
Learning coding
Front End Web Development Techdegree Student 9,937 PointsI remember the !important function and realize the other code didn't work, because of bootstrap. Thanks for staying to it, until it's solved!
Learning coding
Front End Web Development Techdegree Student 9,937 PointsLearning coding
Front End Web Development Techdegree Student 9,937 PointsOk, so I write nav.navbar-nav.li a:hover { color: #3fbf50; }
But this one doesn't work. Our code is similar by the way, exept for the dot (.) in the begin.
How do I make it work?
Redweb FED
15,517 PointsRedweb FED
15,517 PointsSorry I made a mistake which i've just noticed you should write "nav.navbar-nav li a:hover".
When the css is compiled it looks for "." and "#" as ways to identify classes and id's respectively so while the css was rendering because it couldn't find the ".nav" class with a child of ".navbar" you style were just ignored. However because your syntax was correct no error was thrown.
Also one last thin to point out is even the slightest difference in referencing anything in your css file will result in the css being ignored. i.e ".Nav" and ".nav" are two separate classes.