Я создал навигационную панель, и при выборе каждой ссылки в навигационной панели меняется только контент, изменяющийся в теле. Я сделал это с помощью ajax для изменения динамического контента, теперь я могу внести изменения в цвет элементов меню при наведении, но при выборе пункта меню не изменяется цвет.выбранная ссылка не меняет цвет
Также я мог бы сделать так, как только я нажимаю на меню, которое я хотел выбрать, чтобы фоновое изображение менялось, и оно возвращается к старому цвету.
Мой код выглядит следующим образом
HTML:
<div id="menuwrapper">
<ul>
<li>
<a href="#"><img src="images/home.png"></a>
</li>
<li></li>
</ul>
</div>
CSS:
div#menuwrapper ul li a:active {
margin-top: -17px;
margin-left: 0;
width: 26px;
color: red;
height: 56px;
background-color: #000;
}
затем я добавил класс li
и изменил CSS следующим образом
div#menuwrapper li.selected a {
margin-top: -17px;
margin-left: 0;
width: 26px;
color: red;
height: 56px;
background-color: #000;
}
, но ничего не меняется.
Вот мой отредактированный код может любой сделать некоторые предложения по этому
/* Define the body style */
body {
font-family:Arial;
font-size:12px;
}
/* We remove the margin, padding, and list style of UL and LI components */
#menuwrapper ul, #menuwrapper ul li{
margin:0;
padding:0;
list-style:none;
}
/* We apply background color and border bottom white and width to 150px */
#menuwrapper ul li{
background-color:#333333;
border-bottom:solid 1px #222222;
width:56px;
height:56px;
margin-left:-240px;
cursor:pointer;
}
/* We apply the background hover color when user hover the mouse over of the li component */
#menuwrapper ul li:hover{
background-color:#4abbed;
position:relative;
}
/* We apply the link style */
#menuwrapper ul li a{
padding:5px 15px;
color:#ffffff;
display:inline-block;
text-decoration:none;
}
div#menuwrapper ul li a:active {
margin-top: -17px;
margin-left: 0;
width: 26px;
color: red;
height: 56px;
background-color: #000;
}
div#menuwrapper li.selected a {
margin-top: -17px;
margin-left: 0;
width: 26px;
color: red;
height: 56px;
background-color: #000;
}
.nav a {
text-align:center;
float: left;
text-decoration: none;
color: #fff;
padding: 10px;
background: orange;
margin: 0 10px 10px 0;
}
.menu:target
{
background: red;
}
</style>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<div id="header">
<div id="menuwrapper">
<ul class="menu">
<li style="height:5px;background-color:#4abbed;border-bottom:solid 1px #4abbed;">
</li>
<li>
<a href="#" id="menu1" class="menu"><img src="images/home.png"/>
</a>
</li>
<li>
<a href="#" id="menu2" class="menu"><img src="images/Description.png"/>
</a>
</li>
<li>
<a href="#" id="menu3" class="menu" onClick="load('content', 'page2.php');">
<img src="images/Technical.png"/>
</a>
</li>
<li>
<a href="#" id="menu4" class="menu" onClick="load('content', 'page3.php');">
<img src="images/Download.png"/></a>
</li>
</ul>
</div>
</div>
Вы пропустили пробел здесь: 'Lia: active' ->' Ли: с active' – mishik
я исправил его, но по выбору ссылку цвет не меняется – Ambily
Можете ли вы проверить мой ответ? –