Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html CSS使用类更改选定链接的颜色_Html_Css - Fatal编程技术网

Html CSS使用类更改选定链接的颜色

Html CSS使用类更改选定链接的颜色,html,css,Html,Css,我已经创建了一个使用css的基本HTML菜单。为了简单起见,我在整个菜单中使用了“nav”类。但是,由于我使用了一个类,我不确定如何使活动页面的按钮具有新的颜色 基本上,当页面处于活动状态(页面上的用户)时,除了图像以外的所有内容都应该是新颜色 这是我的代码: <!--nav--> <ul class="nav"> <li class="nav"><a href="index.html" target="_self"><

我已经创建了一个使用css的基本HTML菜单。为了简单起见,我在整个菜单中使用了“nav”类。但是,由于我使用了一个类,我不确定如何使活动页面的按钮具有新的颜色

基本上,当页面处于活动状态(页面上的用户)时,除了图像以外的所有内容都应该是新颜色

这是我的代码:

    <!--nav-->
    <ul class="nav">
    <li class="nav"><a href="index.html" target="_self"><img class="nav" src="images/logo_sm.png" width="100" height="50" alt="Welcom to Comp Sale " /></a></li>
    <li class="nav"><a class="nav" href="index.html" target="_self">Home</a></li>
    <li class="nav"><a class="nav" href="Products.html" target="_self">Products</a>        </li>
    <li class="nav"><a class="nav" href="ShoppingCart.html" target="_self">Cart <img class="cart_t" src="images/cart.png" alt="cart.jpg"  /></a></li>
    </ul>
    <!--end nav-->

嗨,你现在做的事有点不对劲。当您对链接和列表项使用
class=“nav”
时。这是非常错误的,您应该使用其他已经在使用的类名。使用类似以下内容:

<li class="nav_li">
   <a class="nav_link" href="index.html" target="_self">
      <img class="nav_image" src="images/logo_sm.png" width="100" height="50" alt="Welcom to Comp Sale " />
   </a>
</li>
这将尝试设置图像的属性。您可以使用
背景色:#hexcode
颜色:#hexcode

但最好的方法仍然是使用不同的类名

$(window).focus(function() { // jQuery

我会为你做这项工作。在这个函数中设置CSS属性。

你应该看看这个问题:这不能用纯CSS来完成。您必须在服务器上或使用javascript标识当前页面。
a.nav img {
/* all the properties for that! */
}
$(window).focus(function() { // jQuery