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 trialHenry Lin
11,636 PointsI am confused by the class on Help Please!
Hi guys, I am currently working on the video "Adding Active States to the Navigation" for PHP. I am not sure how this piece of code affects the website. <li class="books<?php if ($section=="books") {echo " on"; } ?>"> I assume that this code does the following things: li class = books => assign the list value a class named books the php code segment says, hey check if $section variable has a value and if the value is "books". if it is books then set the class = "on" So when we load this page, the browser would apply proper css code to this list item. Am i right ??
2 Answers
Henry Lin
11,636 PointsJust for those who have same question as I did. A html tag(element) could have several class.. that's why we need a php conditional function to control the "on" string ..
I just forgot about the html tag things...
Oliver Burge
1,157 PointsSimply put it is adding the "on" class depending on which section you are currently visiting. If you go into the css file and do a search you will find this : .header .nav li.on a {text-decoration:underline;} which just adds an underline for the "on" class.