CSS- Ckeck And Add Right Arrow Where Li Has Ul
Solution 1:
So there's really no parent selector in CSS, but as you've tagged this with jQuery, we can use the :has() selector to do much the same behavior. Basically, if a LI el contains a UL, we should assume the UL is a submenu, and I will add the 'js-has-a-submenu' class to the anchor el that we're using for the menu items. I've prefixed it with 'js-' simply to reflect that it isn't a statically applied class, but one we'll only use via js.
The code here is actually taken from the menu example I'd referenced in the commments, but then I noticed they'd hard-coded the down-arrow into the menu, which really breaks what you're trying to do, from what I understand. So I removed the down arrow, and used jQuery to apply the class. To understand the menus themselves, please do go read this, as I think it does pretty well (not a fan of the pink, but its css).
$("li:has(ul)").find("a:eq(0)").addClass("js-has-a-submenu");
body {
background: #333;
}
.clearfix:after {
display: block;
clear: both;
}
/*----- Menu Outline -----*/
.menu-wrap {
width: 100%;
box-shadow: 0px 1px 3px rgba(0, 0, 0, 0.2);
background: #3e3436;
}
.menu {
width: 1000px;
margin: 0px auto;
}
.menu li {
margin: 0px;
list-style: none;
font-family: 'Ek Mukta';
}
.menu a {
text-decoration:none;
transition: all linear 0.15s;
color: #919191;
}
.menu li:hover > a,
.menu .current-item > a {
text-decoration: none;
color: #be5b70;
}
.menu .arrow {
font-size: 11px;
line-height: 0%;
}
/*----- Top Level -----*/
.menu > ul > li {
float: left;
display: inline-block;
position: relative;
font-size: 19px;
}
.menu > ul > li > a {
padding: 10px 40px;
display: inline-block;
text-shadow: 0px 1px 0px rgba(0, 0, 0, 0.4);
}
.menu > ul > li:hover > a,
.menu > ul > .current-item > a {
background: #2e2728;
}
/*----- Bottom Level -----*/
.menu li:hover .sub-menu {
z-index: 1;
opacity: 1;
}
.sub-menu {
width: 160%;
padding: 5px 0px;
position: absolute;
top: 100%;
left: 0px;
z-index: -1;
opacity: 0;
transition: opacity linear 0.15s;
box-shadow: 0px 2px 3px rgba(0, 0, 0, 0.2);
background: #2e2728;
}
.sub-menu li {
display: block;
font-size: 16px;
}
.sub-menu li a {
padding: 10px 30px;
display: block;
}
.sub-menu li a:hover,
.sub-menu .current-item a {
background: #3e3436;
}
.js-has-a-submenu::after {
content: " \2193";
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="menu-wrap">
<nav class="menu">
<ul class="clearfix">
<li><a href="#">Home</a></li>
<li>
<a href="#">Movies </a>
<ul class="sub-menu">
<li><a href="#">In Cinemas Now</a></li>
<li><a href="#">Coming Soon</a></li>
<li><a href="#">On DVD/Blu-ray</a></li>
<li><a href="#">Showtimes & Tickets</a></li>
</ul>
</li>
<li><a href="#">T.V. Shows</a></li>
<li><a href="#">Photos</a></li>
<li><a href="#">Site Help</a></li>
</ul>
</nav>
</div>
Solution 2:
What if you would not hide the ul, but the li? Then you could use ::before to get css to insert a little arrow before your ul.
Please have a look at my fiddle https://jsfiddle.net/dL758uba/
/* Menu Styles */
ul {display: inline;}
ul.third-level-menu::before {
content: '-';
position: relative;
left: -200px;
top: 10px;
}
ul::before {
content: '-';
position: relative;
left: 0px;
top: -20px;
}
.third-level-menu
{
position: absolute;
top: 0;
right: -220px;
width: 220px;
list-style: none;
padding: 0;
margin: 0;
}
.third-level-menu > li
{
height: 30px;
background: #999999;
display: none;
}
.third-level-menu > li:hover { background: #CCCCCC; }
.second-level-menu
{
position: absolute;
top: 30px;
left: 0;
width: 200px;
list-style: none;
padding: 0;
margin: 0;
}
.second-level-menu > li
{
position: relative;
height: 30px;
background: #999999;
display: none;
}
.second-level-menu > li:hover { background: #CCCCCC; }
.top-level-menu
{
list-style: none;
padding: 0;
margin: 0;
}
.top-level-menu > li
{
position: relative;
float: left;
height: 30px;
width: 100px;
background: #999999;
}
.top-level-menu > li:hover { background: #CCCCCC; }
.top-level-menu li:hover > ul >li
{
/* On hover, display the next level's menu */
display: block;
}
/* Menu Link Styles */
.top-level-menu a /* Apply to all links inside the multi-level menu */
{
font: bold 14px Arial, Helvetica, sans-serif;
color: #FFFFFF;
text-decoration: none;
padding: 0 0 0 10px;
/* Make the link cover the entire list item-container */
display: block;
line-height: 30px;
}
.top-level-menu a:hover { color: #000000; }
It is a bit rough, but I think it will help you in the right direction.
Post a Comment for "CSS- Ckeck And Add Right Arrow Where Li Has Ul"