When you change the style, the whole menu changes.

<div class="menu"> <?php $arr = array( 'index.php'=>'Главная', 'o_has.php'=>'О нас', 'reg.php'=>'Регистрация', 'kak_podkl.php'=> 'Как подключиться', ''=>'Карта мира', ''=>'Личный кабинет', ''=>'Список изменений', ''=>'Полезные статьи', ''=>'Форум' ); foreach($arr as $key=>$value) { if($_SERVER['PHP_SELF']==$key) echo "<li class=\"menu li\"><a href='$key' >$value</a></li>"; else echo "<li id=\"li\"><a href='$key'>$value</a></li>"; } ?> </div> 

and only the last one works

 else echo "<li id=\"li\"><a href='$key'>$value</a></li>";` 

CSS:

 .menu { display:table; width:100%; table-layout:fixed; border-collapse:collapse; } .menu li /*текущая страница*/ { /* градиентное меню */ display:table-cell; background:green; padding:.5em; text-align:center; border:2px solid black; background: green; /* Для старых браузров */ background: linear-gradient(to top, green, black); padding: 10px; border: 1px solid #333; } (решетка)li /*текущая страница*/ { /* градиентное меню */ display:table-cell; background:green; padding:.5em; text-align:center; border:2px solid black; background: green; /* Для старых браузров */ background: linear-gradient(to top, black, black); padding: 10px; border: 1px solid #333; } 

Help modify the code so that only the current menu item is highlighted.

  • You have a lot of mistakes here: 1. The rule ".menu li" will not apply to anything, because you have no li elements inside the element with the class menu .... I suspect that the menu class should be near the ul tag; 2 You get more than one element with id = "li" is a gross error. The id must be unique within the page. - Vorobev Alexander

1 answer 1

Perhaps $ _SERVER ['PHP_SELF'] returns '/index.php'. those. with a slash most likely in this case. See what's in $ _SERVER ['PHP_SELF'].

And doing so in the array is not good:

 ''=>'Карта мира', ''=>'Личный кабинет', ''=>'Список изменений', ''=>'Полезные статьи', ''=>'Форум' 

write better without keys

 'Карта мира', 'Личный кабинет', 'Список изменений', 'Полезные статьи', 'Форум'