Navbar主动链接与透明三角形 [英] Navbar active link with a transparent triangle

查看:133
本文介绍了Navbar主动链接与透明三角形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您知道如何使用CSS吗?

You know how to do this using CSS?

在我的导航栏中,我想看到一个透明的三角形到活动链接。
如果我创建一个带有透明三角形的PNG图像,并使用它:

In my navbar I would like to see a transparent triangle to the active link. If I create a PNG image with a transparent triangle and use it like this:

background: rgba (0,0,0,0.4) url (triangle.png) no-repeat bottom center;

这不能正常工作,因为在我的三角形下显示透明rgba颜色 rgba (0,0,0,0.4) ...

this does not work properly because under my triangle shows the transparent rgba color rgba(0,0,0,0.4) ...

我想这样做,以便在滚动页面时产生很好的效果。

I would like to do this to make a nice effect when scrolling the page. It is possibile?

推荐答案

演示
您可以使用:之前:之后伪元素达到此效果。

Demo You can use the :before and :after pseudo elements to achieve this effect.

<nav>
    <ul>
        <li class="active">homepage</li>
        <li>option2</li>
        <li>option3</li>
    </ul>
</nav>

nav {
    position: fixed;
    background-color: rgba(0,0,0,.7);
    display: block;
    width: 100%;
    padding: 10px 0;
    color: white;
    font-size: 1.5em;
}

ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

ul li {
    float: left;
    width: auto;
    padding: 0 20px;
    position: relative;
}

nav li:before,
nav li:after {
    content: '';
    position: absolute;
    bottom: -35px;
    left: 0;
    right: 0;
    height: 5px;
    border: 10px transparent solid;
    border-top-color: rgba(0,0,0,.7);
    border-left-width: 0;
    border-right-width: 0;
}
nav li:before {
    right: 50%;
}
nav li:after {
    left: 50%;
}

nav li.active:before {
    border-right-width: 10px;
}

nav li.active:after {
    border-left-width: 10px;
}

nav li:last-child:after { /* covers the bottom of the navigation bar all the way to the right */
    right: -9999999px;
}






使用链接的另一个解决方案

<nav>
    <ul>
        <li><a href="#" class="active">homepage</a></li>
        <li><a href="#">option2</a></li>
        <li><a href="#">option3</a></li>
    </ul>
</nav>

这篇关于Navbar主动链接与透明三角形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆