简体   繁体   English

引导程序更改导航栏上悬停时i类的颜色?

[英]Bootstrap changing the color of i class on hover in navbar?

I was searching on the internet for some ideas, and came across this: http://iarouse.com/dist-flatify/v1.1/index.html#/dashboard 我在互联网上搜索一些想法,并偶然发现: http : //iarouse.com/dist-flatify/v1.1/index.html#/dashboard

Here you see an sidebar with navigation. 在这里,您会看到带有导航的侧栏。 And if you hover over it. 如果将鼠标悬停在它上面。 You can see an specified color over the . 您可以在上看到指定的颜色。 Now I wonder how they did this. 现在我想知道他们是如何做到的。 I tried this: 我尝试了这个:

li:hover > i {
    background-color: green;
}

But that didn't seem to work. 但这似乎没有用。

EDIT: 编辑:

HTML code (sorry for not including): HTML代码(不包括在内):

<ul class="sidebar-menu">
                    <li class="active">
                        <a href="index.html">
                            <i class="fa fa-dashboard"></i> <span>Dashboard</span>
                        </a>
                    </li>
                    <li>
                        <a href="widgets.html">
                            <i class="fa fa-th"></i> <span>Widgets</span> <small class="badge pull-right bg-green">new</small>
                        </a>
                    </li>
                    <li class="treeview">
                        <a href="#">
                            <i class="fa fa-bar-chart-o"></i>
                            <span>Charts</span>
                            <i class="fa fa-angle-left pull-right"></i>
                        </a>
                        <ul class="treeview-menu">
                            <li><a href="charts/morris.html"><i class="fa fa-angle-double-right"></i> Morris</a></li>
                            <li><a href="charts/flot.html"><i class="fa fa-angle-double-right"></i> Flot</a></li>
                            <li><a href="charts/inline.html"><i class="fa fa-angle-double-right"></i> Inline charts</a></li>
                        </ul>
                    </li>
                    <li class="treeview">
                        <a href="#">
                            <i class="fa fa-laptop"></i>
                            <span>UI Elements</span>
                            <i class="fa fa-angle-left pull-right"></i>
                        </a>

                    <li class="treeview">
                        <a href="#">
                            <i class="fa fa-folder"></i>  Multilevel Menu
                            <i class="fa fa-angle-left pull-right"></i>
                        </a>

                        <ul class="treeview-menu">
                            <li class="treeview">
                                <a href="#">
                                    First level
                                    <i class="fa fa-angle-left pull-right"></i>
                                </a>

                                <ul class="treeview-menu">
                                    <li class="treeview">
                                        <a href="#">
                                            Second level
                                            <i class="fa fa-angle-left pull-right"></i>
                                        </a>

                                        <ul class="treeview-menu">
                                            <li>
                                                <a href="#">Third level</a>
                                            </li>
                                        </ul>
                                    </li>
                                </ul>
                            </li>
                        </ul>
                    </li>
                </ul>

EDIT2: most people dont understand the question so let me explain on a other way. EDIT2:大多数人不理解这个问题,所以让我用另一种方式解释。 For example we use the navbar on this page: http://almsaeedstudio.com/AdminLTE/ 例如,我们在此页面上使用导航栏: http : //almsaeedstudio.com/AdminLTE/

Now what I want is when I hover this happens: http://prntscr.com/5526kp 现在,我要的是悬停时发生这种情况: http : //prntscr.com/5526kp

Just like on this website: http://iarouse.com/dist-flatify/v1.1/index.html#/dashboard 就像在此网站上一样: http : //iarouse.com/dist-flatify/v1.1/index.html#/dashboard

If you use your debugger to inspect the sidebar, you'll see that underneath each list item element is a colored span with its left property set to -47px, making it hidden. 如果使用调试器检查侧栏,则会看到每个列表项元素下面是一个彩色的跨度,其left属性设置为-47px,使其隐藏。 That span also has a CSS transition property which is activated when the user hovers over the link. 该范围还具有CSS过渡属性,当用户将鼠标悬停在链接上时会激活该属性。 When that happens, the span's left property transitions to 0, creating the effect you are looking for. 发生这种情况时,跨度的left属性会转换为0,从而创建您要查找的效果。

Here's a fiddle of the general idea that should get you started down the right track. 这是应该使您正确入门的一般想法一个小提琴 I was fooling around with it trying to get it right so there's probably some extraneous you don't need to get the job done, but it should give you an idea. 我在鬼混,试图使其正确,所以可能不需要一些多余的东西来完成工作,但这应该可以给您一个想法。 Hope you find this helpful. 希望对您有所帮助。 Let me know if you have any other questions. 如果您还有其他问题,请告诉我。

The HTML: HTML:

<aside id="nav-container">
    <div id="nav-wrapper">
        <ul class="sidebar-menu">
            <li class="active list_item">
                <a href="index.html" class="list_anchor">
                    <i class="fa fa-dashboard fontawesome_icon">
                        <span class="icon-bg orange"></span>
                    </i>
                    <span class="menu_text">Dashboard</span>
                </a>
            </li>
            <li class="list_item">
                <a href="widgets.html" class="list_anchor">
                    <i class="fa fa-th fontawesome_icon">
                        <span class="icon-bg blue"></span>
                    </i>
                    <span class="menu_text">Widgets</span>
                </a>
            </li>
            <li class="treeview list_item">
                <a href="#" class="list_anchor">
                    <i class="fa fa-bar-chart-o fontawesome_icon">
                        <span class="icon-bg green"></span>
                    </i>
                    <span class="menu_text">Charts</span>
                </a>
            </li>
        </ul>                           
    </div>
</aside>

And the CSS: 和CSS:

#nav-container {
    margin-left: -47px;
}

.sidebar-menu, .treeview-menu {
    list-style-type: none;
}

.list_item {
    width: 218px;
    height: 50px;
    position: relative;
    margin: 0;
}

.list_anchor {
    width: 188px;
    height: 19px;
    padding: 15px;
}

.fontawesome_icon {
    width: 49px;
    height: 50px;
    line-height: 50px;
    text-align: center;
    margin: -15, 10, -15, -15;
    position: relative;
    display: block;
    float: left;
    border-right: 1px solid #e5e5e5;
}

.fontawesome_icon:before {
    position: relative;
    z-index: 1;
}

.fa-dashboard {
    line-height: 50px;
    width: 49px;
    text-align: center;
}

.menu_text {
    margin-top: 15px;
    position: absolute;
}

.icon-bg {
    position: absolute;
    width: 50px;
    height: 50px;
    left: -47px;
    transition: left 0.2s ease-in-out 0s;
}

li:hover > a > i .icon-bg {
    left: 0;
}

.menu_text {
    text-align: left;
    line-height: 20px;
    margin: -15, 10, -15, -15;
    list-style-position: outside;
}

.orange {
    background-color: #E2B721;
}

.blue {
    background-color: #1E23EE;
}

.green {
    background-color: #58E91B;
}

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

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