简体   繁体   English

圆角菜单-当前页面项目

[英]Rounded Corner Menu- Current Page Item

I'm working on a webpage that has a menu with rounded corners. 我正在处理一个带有圆角菜单的网页。 I'm using a theme in WordPress and modifying it, so I'm starting with something someone else has created. 我正在WordPress中使用主题并对其进行修改,所以我从别人创建的东西开始。 I'm middle of the road when it comes to CSS and html- I can kludge things together, but it often isn't exactly elegant and advanced things are beyond me. 在CSS和html方面,我处于中间位置-我可以将所有内容融合在一起,但是通常情况并非完全如此,高级的东西超出了我的范围。

Anyway, my problem is this- The menu items change color when the mouse is hovered over them, and have yet a different color when the item represents the current page. 无论如何,我的问题是-菜单项在鼠标悬停在菜单项上时会更改颜色,而在菜单项代表当前页面时却具有不同的颜色。 The normal menu and the hover items have rounded corners, but not the current page item. 普通菜单和悬停项目带有圆角,但当前页面项目没有。 This only matters for the left side of the item on the farthest left. 这仅对最左侧的项目左侧有意义。

I did find a bit of CSS for the hover state of that item that works, which is as follows: 我确实找到了一些适用于该项目的悬停状态的CSS,如下所示:

.menu > li:first-child:hover, 
.menu > li:first-child:hover a {
    border-top-left-radius: 6px;
    border-bottom-left-radius: 6px; }

However, I have no idea how to take this same principle and apply it to the current item class. 但是,我不知道如何采用相同的原理并将其应用于当前的项目类。 This is what I tried: 这是我尝试的:

.menu .current_page_item a > li:first-child:,
.menu  .current_menu_item a > li:first-child: {
    border-top-left-radius: 6px;
    border-bottom-left-radius: 6px;

It didn't work, of course. 当然,它没有用。 As I say, it's really a shot in the dark. 正如我所说,这确实是黑暗中的一枪。

You can select the first menu item anchor with: 您可以通过以下方式选择第一个菜单项锚点:

.menu > li:first-child > a {
    border-top-left-radius:6px;
    border-bottom-left-radius:6px;
}

This targets: 该目标是:

the menu > the first list item inside that menu > the anchor immediately inside that list item

This would be safer than targeting the .current-item class since you're trying to target the first list item specifically to blend it with existing elements, whereas the .current-item class can be used on every menu item. 这比定位.current-item类更安全,因为您正试图定位第一个列表项,以专门将其与现有元素混合,而.current-item类可以在每个菜单项上使用。

The problem with your original selector syntax was that this: 原始选择器语法的问题是:

.menu .current_page_item a > li:first-child:

is trying to select: 正在尝试选择:

the menu > the current list item > the anchor inside that item >
the first list item immediately inside that item

Most of that isn't in the page's HTML. 大多数都不在页面的HTML中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM