I want to make the easiest css for menus. There’s an outer div and an inner anchor. If the outer’s class is the same as the inner’s id, that will be active styled.
Example code:
<div class='<?php echo $_GET['menu']; ?>'>
<a href="index.php?menu=menu1" id='menu1'>Menu 1</a>
<a href="index.php?menu=menu2" id='menu2'>Menu 2</a>
<a href="index.php?menu=menu3" id='menu3'>Menu 3</a>
<a href="index.php?menu=menu4" id='menu4'>Menu 4</a>
<a href="index.php?menu=menu5" id='menu5'>Menu 5</a>
</div>
and I don’t want to write a lot of css, like:
.menu1 #menu1, .menu2 #menu2, .menu3 ....
{ /*active stlye*/}
so I want the following: if the classname is the same of the id under it would be active.
Thanks in advance.
That’s not possible. CSS isn’t a programming language, you have to fully specify every selector.
But since you already work with PHP it would be a lot easier if you apply the class to one of your anchor tags:
You have to either specify a bunch of selectors or add code to your PHP script.