想要更改当前页面的选项卡图像
我有一个 Django Web 应用程序,它具有水平导航功能,并且选项卡水平移动。每个链接都会查找名为 tab.png 的图像选项卡。我还添加了一个悬停属性。
现在,我想更改所选选项卡菜单(当前页面)的选项卡图像。因此,无论当前页面是什么,将选项卡图像更改为 tab2.png。唯一的问题是我不知道如何正确地做到这一点。
base_menu.html
{% extends "base.html" %}
{% block content %}
<ol id="toc">
<li><a href="{% url mmc.views.return_clients %}"><span>Home</span></a></li>
<li><a href="{% url mmc.views.quote_step1 %}"><span>Create quote/order</span></a></li>
<li><a href="{% url mmc.views.search_item %}"><span> Item Search</a></span></li>
<li><a href="{% url mmc.views.order_list %}"><span>Storage orders</span></a></li>
</ol>
<div id="right_content">
{% block right_content %}
{% endblock %}
</div>
{% endblock %}
base.css
ol#toc {
height: 2em;
list-style: none;
margin: 0;
padding: 0;
}
ol#toc li {
background:#ffffff url(../images/tab.png);
float: left;
margin: 0 1px 0 0;
}
ol#toc span {
background: url(../images/tab.png) 100% 0;
display: block;
line-height: 2em;
padding-right: 10px;
}
ol#toc a {
color: #000000;
height: 2em;
float: left;
text-decoration: none;
padding-left: 10px;
}
ol#toc a:hover {
background: url(../images/tab2.png);
text-decoration: underline;`
}
ol#toc a:hover span {
background: url(../images/tab2.png) 100% 0;
background-position: 100% -120px;
}
I have a django web app that has a horizontal navagation with tabs going horizontally. Each link looks for an image tab called tab.png. I've also included a hover property as well.
Now, I want to change tab image for the selected tab menu (current page). So whatever the current page is, change the tab image to tab2.png. The only thing is I am not sure how to do this properly.
base_menu.html
{% extends "base.html" %}
{% block content %}
<ol id="toc">
<li><a href="{% url mmc.views.return_clients %}"><span>Home</span></a></li>
<li><a href="{% url mmc.views.quote_step1 %}"><span>Create quote/order</span></a></li>
<li><a href="{% url mmc.views.search_item %}"><span> Item Search</a></span></li>
<li><a href="{% url mmc.views.order_list %}"><span>Storage orders</span></a></li>
</ol>
<div id="right_content">
{% block right_content %}
{% endblock %}
</div>
{% endblock %}
base.css
ol#toc {
height: 2em;
list-style: none;
margin: 0;
padding: 0;
}
ol#toc li {
background:#ffffff url(../images/tab.png);
float: left;
margin: 0 1px 0 0;
}
ol#toc span {
background: url(../images/tab.png) 100% 0;
display: block;
line-height: 2em;
padding-right: 10px;
}
ol#toc a {
color: #000000;
height: 2em;
float: left;
text-decoration: none;
padding-left: 10px;
}
ol#toc a:hover {
background: url(../images/tab2.png);
text-decoration: underline;`
}
ol#toc a:hover span {
background: url(../images/tab2.png) 100% 0;
background-position: 100% -120px;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在这个布局中,似乎不可能仅使用 css,因为您的 'li' 或 'a' 没有类似 id="current" 的内容。
顺便说一句,使用这种样式,您可以在“span”顶部有一个带有选项卡的“a”,在带有选项卡的“li”顶部有一个选项卡。我说有点过分了?
当您添加当前的li时,这是您唯一需要的CSS...不需要所有其他背景。
In this layout it doesnt seem to be possible using just css, since your 'li' or 'a' doesnt have something like id="current" .
Btw, using this style you can have an 'a' with a tab on top of a 'span' with a tab on top of a 'li' that has a tab. Kinda overkill id say?
This is the only css you need when you add a current li... all the other backgrounds are not needed.
@Shehzad009;在
a
标签中提供您的图像对于当前页面
,您可以根据页面为其创建一个类,例如.current
$\&chane。HTML
@Shehzad009; Give your image in
a
tag & forcurrent page
you can create a class for it like.current
$\&chane according to the page.HTML
这是一个 javascript 行,用于将“当前”类设置为 .
here is a javascript line to set "current" class to .