css - Applying &:before to top level of menu only -
i have following html structure cannot edit:
<div id="menu"> <ul class="nav nav-pills nav-stacked"> <li class="active"><a href="#">home</a> <ul class="sub-menu"> <li class="active"><a href="#">home</a></li> <li><a href="#">profile</a></li> <li><a href="#">messages</a></li> </ul> </li> <li><a href="#">profile</a></li> <li><a href="#">messages</a></li> </ul> </div>
i using sass style triangle inserted before text inside link:
#menu{ width:300px; .nav li{ a{ border-bottom: 1px solid #ededde; &:before { content: ""; display: inline-block; width: 0; height: 0; border-top: 4px solid transparent; border-bottom: 4px solid transparent; border-left: 4px solid #333; margin-left: 5px; margin-right: 5px; position: relative; } } } .sub-menu { list-style:none; padding-left: 30px; border-bottom: 0; } }
codepen bootstrap added here: http://codepen.io/guerrillacoder/pen/jpbmqg?editors=110
the effect desire inserted in top level of menu, , if class "active" there triangle point down instead of right.
i going round in circles, cannot figure out how either remove inserted content, hide or alter selector top level. trying stop underline spilling sub-menu.
can give me tips?
you should apply generic rules (the ones can/will affect :after
pseudo-element of time) .nav a
selector (which broad selector, covering a
elements in .nav
).
then, specific in targeting ones want special behviour:
.nav{ a{ border-bottom: 1px solid #ededde; &:before { display: inline-block; width: 0; height: 0; margin-left: 5px; margin-right: 5px; position: relative; } } & > li > a:before { content: ""; border-top: 4px solid transparent; border-bottom: 4px solid transparent; border-left: 4px solid #333; } & > li.active a:before { border-top: 4px solid #333; border-right: 4px solid transparent; border-left: 4px solid transparent; }
i've used descendant selectors ensure direct children of top level affected.
full example:
Comments
Post a Comment