CSS - 使用多个类实现悬停效果

发布于 2024-10-15 04:59:11 字数 2734 浏览 0 评论 0原文

我正在尝试向导航栏的悬停状态添加一个小三角形。

HTML:

        <div id="menu_bars">
            <div id="main_bar">
                <ul>
                    <li class="maintabs maintabs_tri"><a href="#">Over</a></li>
<li class="maintabs maintabs_tri"><a href="#">Collar</a></li>
<li class="maintabs maintabs_tri"><a href="#">Bod</a></li>
                </ul>           
            </div>  

            <div id="css_arrow" class="maintabs_tri"><a href="#"></a>
            </div>
        </div>

“main_bar”div 创建一个水平导航菜单。 div id 'css_arrow' 用于创建一个箭头,该箭头将在悬停状态下显示。 我为它们设计了一个名为“maintabs_tri”的类,其中包括三角形和“main_tab”导航菜单,这样当悬停状态变为活动状态时,三角形就会出现在导航栏上。

CSS:

/* START OF MAIN BAR */
#main_bar ul {
    float: left;
    width: 630px;
    height: 48px;
}

.maintabs {
    display: inline-block;
    width: 25%;
    list-style-type: none;
    background: rgba(237,237,237,1);
    background: -moz-linear-gradient(top, rgba(255,255,255,1), rgba(237,237,237,1)); 
    background: -webkit-gradient(linear, top, bottom, from(rgba(255,255,255,1)), to(rgba(237,237,237,1)));
    -moz-box-shadow: 1px 2px 2px rgba(0,0,0,0.2);
    -webkit-box-shadow: 1px 2px 2px rgba(0,0,0,0.2);
    box-shadow: 1px 2px 2px rgba(0,0,0,0.2);
    -webkit-transition-property: 
}

.maintabs:first-child {
    -webkit-border-top-left-radius: 6px;
    -webkit-border-bottom-left-radius: 6px;
    -moz-border-radius-topleft: 6px;
    -moz-border-radius-bottomleft: 6px;
    border-top-left-radius: 6px;
    border-bottom-left-radius: 6px; 
}

.maintabs:last-child {
    -webkit-border-top-right-radius: 6px;
    -webkit-border-bottom-right-radius: 6px;
    -moz-border-radius-topright: 6px;
    -moz-border-radius-bottomright: 6px;
    border-top-right-radius: 6px;
    border-bottom-right-radius: 6px;        
}

.maintabs a {
    display: block;
    text-decoration: none;
    text-align: center;
    vertical-align: middle;
    line-height: 14px;
    text-shadow: 0px 1px 2px rgba(0,0,0,0.3);
    padding: 18px 0px;
}

.maintabs ul {
    display: none;
    list-style-type: none;
}

.maintabs ul li a {
    text-decoration: none;
}
/* END OF MAIN BAR */



/* TRIANGLE ------ for testing, to be used with hover later */
#css_arrow {
    border-color: transparent transparent rgba(111,46,11,0.0) transparent;
    border-style: solid;
    border-width: 8px;
    height: 0;
    width: 0;
    position: absolute;
    top: 34px;
    left: 78px;
}

.maintabs_tri a:hover {
    border-color: transparent transparent rgba(111,46,11,1) transparent;
}

有人可以分享为什么这不起作用吗?我这辈子都无法弄清楚...

I am trying to add a mini triangle to the hover state of navigation bar.

HTML:

        <div id="menu_bars">
            <div id="main_bar">
                <ul>
                    <li class="maintabs maintabs_tri"><a href="#">Over</a></li>
<li class="maintabs maintabs_tri"><a href="#">Collar</a></li>
<li class="maintabs maintabs_tri"><a href="#">Bod</a></li>
                </ul>           
            </div>  

            <div id="css_arrow" class="maintabs_tri"><a href="#"></a>
            </div>
        </div>

The 'main_bar' div creates a horizontal navigation menu.
The div id 'css_arrow' is being use to create an arrow which will show up on hover state.
I game them all a class called 'maintabs_tri' which includes the triangle and the 'main_tab' navigation menu, so that when the hover state becomes active, the triangle appears on the navigation bar.

CSS:

/* START OF MAIN BAR */
#main_bar ul {
    float: left;
    width: 630px;
    height: 48px;
}

.maintabs {
    display: inline-block;
    width: 25%;
    list-style-type: none;
    background: rgba(237,237,237,1);
    background: -moz-linear-gradient(top, rgba(255,255,255,1), rgba(237,237,237,1)); 
    background: -webkit-gradient(linear, top, bottom, from(rgba(255,255,255,1)), to(rgba(237,237,237,1)));
    -moz-box-shadow: 1px 2px 2px rgba(0,0,0,0.2);
    -webkit-box-shadow: 1px 2px 2px rgba(0,0,0,0.2);
    box-shadow: 1px 2px 2px rgba(0,0,0,0.2);
    -webkit-transition-property: 
}

.maintabs:first-child {
    -webkit-border-top-left-radius: 6px;
    -webkit-border-bottom-left-radius: 6px;
    -moz-border-radius-topleft: 6px;
    -moz-border-radius-bottomleft: 6px;
    border-top-left-radius: 6px;
    border-bottom-left-radius: 6px; 
}

.maintabs:last-child {
    -webkit-border-top-right-radius: 6px;
    -webkit-border-bottom-right-radius: 6px;
    -moz-border-radius-topright: 6px;
    -moz-border-radius-bottomright: 6px;
    border-top-right-radius: 6px;
    border-bottom-right-radius: 6px;        
}

.maintabs a {
    display: block;
    text-decoration: none;
    text-align: center;
    vertical-align: middle;
    line-height: 14px;
    text-shadow: 0px 1px 2px rgba(0,0,0,0.3);
    padding: 18px 0px;
}

.maintabs ul {
    display: none;
    list-style-type: none;
}

.maintabs ul li a {
    text-decoration: none;
}
/* END OF MAIN BAR */



/* TRIANGLE ------ for testing, to be used with hover later */
#css_arrow {
    border-color: transparent transparent rgba(111,46,11,0.0) transparent;
    border-style: solid;
    border-width: 8px;
    height: 0;
    width: 0;
    position: absolute;
    top: 34px;
    left: 78px;
}

.maintabs_tri a:hover {
    border-color: transparent transparent rgba(111,46,11,1) transparent;
}

Could someone share why this is not working? I cannot figure out for the life of me...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

不一样的天空 2024-10-22 04:59:11

添加到 .maintabs_tri a:hover 中:border-bottom: 3pxsolid #000 修复了 Chrome 中的问题。

问题是没有定义 border-widthborder-style

Adding to .maintabs_tri a:hover this: border-bottom: 3px solid #000 fixes it in Chrome.

The issue was that there was no border-width or border-style defined.

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