make a transparent arrow on menu
by Kheema Pandey
HTML
<nav role='navigation'>
<ul>
<li><a class="current" href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Clients</a></li>
<li><a href="#">Contact Us</a></li>
</ul>
</nav>
CSS
body {
background: url(http://lorempixel.com/output/abstract-q-c-500-500-2.jpg);
}
* {
margin: 0;
padding: 0;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
ul, li {
padding: 0;
list-style: none;
}
ul {
text-align: center;
margin-top:15px;
}
li {
display: inline-block;
background-color: red;
font-size:0;
position: relative;
}
a {
display: block;
text-decoration: none;
font-size:1rem;
color:white;
padding: 1rem 2rem;
position: relative;
}
li:before,
li:after {
position: absolute;
content:"";
top:100%;
width:calc(50% - 12px); /* allows to width of triangle*/
height:12px;
background-color: red;
}
li:before{
left:0;
}
li:after {
right:0;
}
a:before {
position: absolute;
content:"";
z-index:-1; /* hide behind link */
border:12px solid red;
top:100%;
left:50%;
transform:translate(-50%, -50%); /* center the pseudo element and only show bottom half*/
}
a.current:before {
border-bottom-color:transparent; /* our triangle */
}
JavaScript
$("a").click(function () {
$(this).toggleClass("current");
$("a").not(this).removeClass("current");
});