我在互联网上搜索一些想法,并发现了这个: http://iarouse.com/dist-flatify/v1.1/index.html#/dashboard
在这里您可以看到带导航的侧边栏。如果你将鼠标悬停在它上面。你可以看到指定的颜色。现在我想知道他们是怎么做到的。我试过这个:
li:hover > i {
background-color: green;
}
但这似乎不起作用。
编辑:
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: 大多数人都不明白这个问题,所以让我以另一种方式解释。 例如,我们使用此页面上的导航栏: http://almsaeedstudio.com/AdminLTE/
现在我想要的是当我将鼠标悬停时: http://prntscr.com/5526kp
就像在这个网站上一样:http://iarouse.com/dist-flatify/v1.1/index.html#/dashboard
答案 0 :(得分:1)
如果您使用调试器检查侧边栏,您会看到每个列表项元素下面都是一个彩色范围,其左侧属性设置为-47px,使其隐藏。该跨度还具有CSS转换属性,当用户将鼠标悬停在链接上时,该属性将被激活。当发生这种情况时,span的左侧属性转换为0,从而创建您正在寻找的效果。
这里a fiddle of the general idea应该让你开始走上正轨。我一直在努力让它变得正确,所以可能有一些无关紧要的东西你不需要完成工作,但它应该给你一个想法。希望你觉得这很有帮助。如果您有任何其他问题,请与我们联系。
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>
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;
}