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 {
backgrou开发者_运维百科nd: url(../images/tab2.png) 100% 0;
background-position: 100% -120px;
}
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.
ol#toc li {
background:#ffffff url(../images/tab.png);
float: left;
margin: 0 1px 0 0;
}
ol#toc li#current {
background:#ffffff url(../images/tab2.png);
float: left;
margin: 0 1px 0 0;
}
@Shehzad009; Give your image in a
tag & for current page
you can create a class for it like .current
$\&chane according to the page.
ol#toc a{background: url(http://dummyimage.com/200x32/000/fff&text=normal) 0 0;}
ol#toc a:hover, .current {background: url(http://dummyimage.com/200x32/000/454545&text=hover) 0 0;}
HTML
<ol id="toc">
<li class="current"><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>
here is a javascript line to set "current" class to .
<script type="text/javascript">
$(document).ready( function () {
$("#toc >li >a").each(function (key,object) { if($(object).attr("href") == document.location.pathname) $(object).addClass("current");});
});
</script>
精彩评论