【问题标题】:Highlighting the Menu Item for the Current Page Wordpress突出显示当前页面 Wordpress 的菜单项
【发布时间】:2016-02-25 01:48:12
【问题描述】:

我想用三角形突出显示当前页面的菜单项,我使用了这个代码

.current-menu-ancestor > a,
.current-menu-item > a,
.current-page-ancestor > a,
.current_page_item > a{
background-image:url(‘http://www.dailybodycare.dk/wp-content/uploads/2015/11/triunghi_rosu_meniu.svg’);
background-repeat:no-repeat;
background-position:center bottom;
}

但是当我选择一个子菜单项时,该项目是突出显示的,我不想要那个。当我单击子菜单项时,我只想突出显示没有子菜单项的祖先或父项。

我知道我应该使用这段代码

.main-navigation li.current_page_parent > a {
background-image:url(‘http://www.dailybodycare.dk/wp-content/uploads/2015/11/triunghi_rosu_meniu.svg’);
background-repeat:no-repeat;
background-position:center bottom;
}

或者这个

.main-navigation li.current-page-ancestor > a {
background-image:url(‘http://www.dailybodycare.dk/wp-content/uploads/2015/11/triunghi_rosu_meniu.svg’);
background-repeat:no-repeat;
background-position:center bottom;
}

我认为他们的想法相同,但我不确定如何正确编写代码。

这是我的网址 www dot dailybodycare dot dk

【问题讨论】:

    标签: jquery css wordpress navigation highlight


    【解决方案1】:

    ul.menunav-menu > 添加到选择器的开头,这样它只会针对顶级链接。

    例如,将您当前的选择器更新为:

    ul.menunav-menu > .current-menu-ancestor > a, 
    ul.menunav-menu > .current-menu-item > a, 
    ul.menunav-menu > .current-page-ancestor > a, 
    ul.menunav-menu > .current_page_item > a {
        background-image: url('http://www.dailybodycare.dk/wp-content/uploads/2015/11/triunghi_rosu_meniu.svg');
        background-repeat: no-repeat;
        background-position: center bottom;
    }
    

    【讨论】:

    • 谢谢你的帮助....这正是我想做的,如果不是太多你能告诉我如何用css三角形改变三角形图像(.svg) .curent{ width: 0; height: 0; position: center; content:""; display:block; border-left: 8px solid transparent; border-right: 8px solid transparent; border-bottom: 8px solid #000; left: 50%; margin-top: 60px;} } .curent 它是所有菜单链接的类。再次感谢您的帮助。
    • 用这个替换上面的答案: ul.menunav-menu > .current-menu-ancestor > a, ul.menunav-menu > .current-menu-item > a, ul.menunav-menu > .current-page-ancestor > a, ul.menunav-menu > .current_page_item > a { position:relative; }
    • 然后删除你用于“.curent”的css并添加:ul.menunav-menu > .current-menu-ancestor > a:after, ul.menunav-menu > .current-menu -item > a:after, ul.menunav-menu > .current-page-ancestor > a:after, ul.menunav-menu > .current_page_item > a:after { width: 0;高度:0;位置:绝对;内容:””;显示:块;左边框:8px 纯透明; border-right: 8px 实心透明;边框底部:8px 实心#000;左:50%;底部:0;左边距:-8px; }
    • thx,可以,但是三角形不在文本中间,因为我有 padding: 0 0 0 25px; ,我应该将 left: 50% 增加到 55% 或 60% 吗?
    • 否,改为调整 margin-left 值
    猜你喜欢
    • 2014-09-06
    • 2011-10-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-05
    • 1970-01-01
    相关资源
    最近更新 更多