gpt4 book ai didi

html - 将当前类添加到当前菜单项 CSS

转载 作者:太空宇宙 更新时间:2023-11-04 14:47:57 26 4
gpt4 key购买 nike

只是尝试向当前页面的菜单项添加一个类,以便用户知道他们当前所在的页面。但是背景图像不会显示。我正在将类(class)应用于 <a>但我也将它添加到 <li>

 <div id="menu">
<ul id='foot'>

<li><a class="current" href='index.php'>Home</a></li>
<li><a href='article-list.php?article_type=test0'>Page 0</a></li>
<li><a href='article-list.php?article_type=test'>Page 1</a></li>
<li><a href='article-list.php?article_type=test2'>Page 2</a></li>
<li><a href='chic.php?page=blogs_full'>Page 3</a></li>

</ul>


</div>

样式表:

#menu{height:51px;width:900px;background-image:url(../NEW_images/menu_bg.jpg);background-repeat:repeat-x;}
#menu ul{}
#menu li {display:inline;font: 20px Verdana, Helvetica, sans-serif;margin: 0;padding: 0;}
#menu a {background: url("../images/seperator.gif") bottom right no-repeat;color: #ccc;display: block;float: left;margin: 0;padding: 8px 20px;text-decoration: none;}
#menu a:hover {background: #2580a2 url("../NEW_images/li_bg.jpg") bottom center repeat-x;color: #fff;padding-bottom: 8px;padding: 8px 20px;}
.current{background: #2580a2 url(../NEW_images/li_bg.jpg) bottom center repeat-x;color: #fff;padding-bottom: 8px;padding: 8px 20px;}
#page_num{width:100%; text-align:center; margin:40px 0 20px 0;}

最佳答案

您需要使用 #menu a 来限定您的 .current 选择器,否则它会被之前的选择器覆盖,因为单独的 .current不够具体:

#menu a.current{background: #2580a2 url(../NEW_images/li_bg.jpg) bottom center repeat-x;color: #fff;padding-bottom: 8px;padding: 8px 20px;}

您的 CSS 还可以使用更好的格式,这样很难阅读。

关于html - 将当前类添加到当前菜单项 CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4654197/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com