想要更改当前页面的选项卡图像

发布于 2024-12-03 04:13:59 字数 1643 浏览 2 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

以往的大感动 2024-12-10 04:13:59

在这个布局中,似乎不可能仅使用 css,因为您的 'li' 或 'a' 没有类似 id="current" 的内容。

顺便说一句,使用这种样式,您可以在“span”顶部有一个带有选项卡的“a”,在带有选项卡的“li”顶部有一个选项卡。我说有点过分了?

当您添加当前的li时,这是您唯一需要的CSS...不需要所有其他背景。

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;

}

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;

}
﹎☆浅夏丿初晴 2024-12-10 04:13:59

@Shehzad009;在 a 标签中提供您的图像对于当前页面,您可以根据页面为其创建一个类,例如.current $\&chane。

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>

@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>
ˉ厌 2024-12-10 04:13:59

这是一个 javascript 行,用于将“当前”类设置为 .

<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>

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文