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.

PHP Build a Basic PHP Website (2018) Building a Media Library in PHP Adding Active States to the Navigation

Henry Lin
Henry Lin
11,636 Points

I 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
Henry Lin
11,636 Points

Just 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
Oliver Burge
1,157 Points

Simply 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.