I have an HTML menu in a partial and I want to make the menu items dynamic (changing colors) depending on which page we are at. How can I do that?
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A common trick that is used to alter the appearance of menus to reflect the current page is to put a CSS selector or class that reflects the page name in the body tag.
Once you’ve done that, you can create different styles for each variation of page name that you want.
For example:
Then the CSS can be anything you like, but something like:
This method ensures good separation of concerns: the visual styles (changing of your colors) stay in your stylesheets, and out of your code.