I’ve been reading this site many times for a while. It’s been always quite helpful for lots of things. So thank you guys!
I’m having an issue that I can’t manage to solve. I’ve been deeply looking through other posts here in stackoverflow (really) but even when the information I got it’s quiet clear and the solution seemed straightforward I can’t get this working, sorry.
Basically I have a WordPress site I’m creating with a Main Menu navigation bar. Elements are being shown by using <?php wp_list_pages('title_li='); ?>
and then with CSS I’ve styled all elements in order to show a vertical divider between elements.
The thing is I can’t get the last item to be different to the others (I don’t want it to show a vertical divider because it’s the last one) I’ve tried many options following your kindly advise but didn’t work so I did delete the code from all my failing attempts.
Any help would be much appreciated.
Here’s my code:
<div id="cssmenu">
<ul class="nav" id="primary-nav">
<?php if (is_page()) { $highlight = "page_item"; } else {$highlight = "page_item current_page_item"; } ?>
<li class="<?php echo $highlight; ?>"><a href="<?php bloginfo('url'); ?>">WELCOME</a></li>
<?php wp_list_pages('title_li='); ?>
</ul>
</div>
And the CSS can be found here:
#cssmenu {
height:37px;
display:block;
padding:0;
margin:0 auto;
border: 1px solid #444758;
border-bottom: 1px solid #bbbdc5;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
-webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), inset 0 20px 20px rgba(255, 255, 255, 0.12), 0 1px 1px #9c9c9c, inset 0 -1px 0 #343746;
-moz-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), inset 0 20px 20px rgba(255, 255, 255, 0.12), 0 1px 1px #9c9c9c, inset 0 -1px 0 #343746;
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5), inset 0 20px 20px rgba(255, 255, 255, 0.14), inset 0 -1px 0 #343746;
}
#cssmenu > ul {list-style:inside none; padding:0; margin:0;}
#cssmenu > ul > li {list-style:inside none; padding:0; margin:0; float:left; display:block; position:relative;}
#cssmenu > ul > li > a{ outline:none; display:block; position:relative; padding:9px 37px; font-size: 15px; letter-spacing: 0; text-align:center; text-decoration:none; text-shadow:0 -1px 0 #000 !important; text-transform: uppercase; }
#cssmenu > ul > li.last-item > a{ padding-right:34px; }
#cssmenu > ul > li:first-child > a{border-radius:4px 0 0 4px;}
#cssmenu > ul > li > a:after{ content:''; position:absolute; border-right:1px solid; top:0; bottom:0; right:-2px; z-index:99; }
#cssmenu > ul > li.last-item > a:after{ border:none; }
#cssmenu ul li.has-sub:hover > a:after{top:0; bottom:0;}
#cssmenu > ul > li.has-sub > a:before{ content:''; position:absolute; top:18px; right:6px; border:4px solid transparent; border-top:4px solid #fff; }
#cssmenu > ul > li.has-sub:hover > a:before{top:19px;}
#cssmenu ul li.has-sub:hover > a{ background:#3f3f3f; border-color:#3f3f3f; padding-bottom:13px; padding-top:13px; top:-1px; z-index:999; }
#cssmenu ul li.has-sub:hover > ul, #cssmenu ul li.has-sub:hover > div{display:block;}
#cssmenu ul li.has-sub > a:hover{background:#3f3f3f; border-color:#3f3f3f;}
#cssmenu ul li > ul, #cssmenu ul li > div{ display:none; width:auto; position:absolute; top:38px; padding:10px 0; background:#3f3f3f; border-radius:0 0 4px 4px; z-index:999; }
#cssmenu ul li > ul{width:200px;}
#cssmenu ul li > ul li{display:block; list-style:inside none; padding:0; margin:0; position:relative;}
#cssmenu ul li > ul li a{ outline:none; display:block; position:relative; margin:0; padding:8px 20px; font:10pt Arial, Helvetica, sans-serif; color:#fff; text-decoration:none; text-shadow:1px 1px 0 rgba(0,0,0, 0.5); }
#cssmenu, #cssmenu > ul > li > ul > li a:hover {
background: #3e4151;
background-repeat: repeat-x;
background-image: -khtml-gradient(linear, left top, left bottom, from(#838796), to(#3e4151));
background-image: -moz-linear-gradient(top, #838796, #3e4151);
background-image: -ms-linear-gradient(top, #838796, #3e4151);
background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #838796), color-stop(100%, #3e4151));
background-image: -webkit-linear-gradient(top, #838796, #3e4151);
background-image: -o-linear-gradient(top, #838796, #3e4151);
background-image: linear-gradient(top, #838796, #3e4151);
filter:progid:DXImageTransform.Microsoft.gradient( startColorstr='#838796', endColorstr='#3e4151',GradientType=0 );
}
#cssmenu{border-color:#353749;}
#cssmenu > ul > li > a{border-right:1px solid #4e5262; color:#fff !important;}
#cssmenu > ul > li > a.last-item{border:none;}
#cssmenu > ul > li > a:after{border-color:#a6a9b4;}
#cssmenu > ul > li > a:hover {
background: #2666c3;
background-repeat: repeat-x;
background-image: -khtml-gradient(linear, left top, left bottom, from(#1c356b), to(#2666c3));
background-image: -moz-linear-gradient(top, #1c356b, #2666c3);
background-image: -ms-linear-gradient(top, #1c356b, #2666c3);
background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #1c356b), color-stop(100%, #2666c3));
background-image: -webkit-linear-gradient(top, #1c356b, #2666c3);
background-image: -o-linear-gradient(top, #1c356b, #2666c3);
background-image: linear-gradient(top, #1c356b, #2666c3);
filter:progid:DXImageTransform.Microsoft.gradient( startColorstr='#1c356b', endColorstr='#2666c3',GradientType=0 );
-webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), inset 0 20px 20px rgba(255, 255, 255, 0.12), 0 1px 1px #9c9c9c, inset 0 -1px 0 #343746;
-moz-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), inset 0 20px 20px rgba(255, 255, 255, 0.12), 0 1px 1px #9c9c9c, inset 0 -1px 0 #343746;
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5), inset 0 20px 20px rgba(255, 255, 255, 0.14), inset 0 -1px 0 #343746;
}
#cssmenu ul li .current_page_item a,#cssmenu ul li .current_page_item a:hover{
background: #2666c3;
background-repeat: repeat-x;
background-image: -khtml-gradient(linear, left top, left bottom, from(#2666c3), to(#1c356b));
background-image: -moz-linear-gradient(top, #2666c3, #1c356b);
background-image: -ms-linear-gradient(top, #2666c3, #1c356b);
background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #2666c3), color-stop(100%, #1c356b));
background-image: -webkit-linear-gradient(top, #2666c3, #1c356b);
background-image: -o-linear-gradient(top, #2666c3, #1c356b);
background-image: linear-gradient(top, #2666c3, #1c356b);
filter:progid:DXImageTransform.Microsoft.gradient( startColorstr='#2666c3', endColorstr='#1c356b',GradientType=0 );
-webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), inset 0 20px 20px rgba(255, 255, 255, 0.12), 0 1px 1px #9c9c9c, inset 0 -1px 0 #343746;
-moz-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), inset 0 20px 20px rgba(255, 255, 255, 0.12), 0 1px 1px #9c9c9c, inset 0 -1px 0 #343746;
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5), inset 0 20px 20px rgba(255, 255, 255, 0.14), inset 0 -1px 0 #343746;
}
#cssmenu ul li.current_page_item a{
background: #2666c3;
background-repeat: repeat-x;
background-image: -khtml-gradient(linear, left top, left bottom, from(#2666c3), to(#1c356b));
background-image: -moz-linear-gradient(top, #2666c3, #1c356b);
background-image: -ms-linear-gradient(top, #2666c3, #1c356b);
background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #2666c3), color-stop(100%, #1c356b));
background-image: -webkit-linear-gradient(top, #2666c3, #1c356b);
background-image: -o-linear-gradient(top, #2666c3, #1c356b);
background-image: linear-gradient(top, #2666c3, #1c356b);
filter:progid:DXImageTransform.Microsoft.gradient( startColorstr='#2666c3', endColorstr='#1c356b',GradientType=0 );
-webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), inset 0 20px 20px rgba(255, 255, 255, 0.12), 0 1px 1px #9c9c9c, inset 0 -1px 0 #343746;
-moz-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), inset 0 20px 20px rgba(255, 255, 255, 0.12), 0 1px 1px #9c9c9c, inset 0 -1px 0 #343746;
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5), inset 0 20px 20px rgba(255, 255, 255, 0.14), inset 0 -1px 0 #343746;
}
Thank you guys, I really appreciate you help 🙂
Did you try that to get the last item ?
You can use either
OR
The “last-of-type” is good if you have “subitems” or “submenus” (
<ul><ul><li>
) since it’s going to work anyways, but it’s less compatible with browsers… you can also point that with multiple “last-child” rules….Check your CSS specificity too. Sometimes you may need to use a higher specificity to get what you want.
You should use “+” selector, it’s from CSS 2.0 and very powerful,even for IE 7 too.
cssmenu ul li{border:none}
cssmenu ul li+li{border-left:1px solid #colorcode;}
This will make every “li” has the vertical line on left side (instead using lines on right side) except the first one.
For the last item menu:
For the item before the last, if you need:
I guess you will have to add this rule