I’m trying to achieve this mouseover effect with the smallest footprint possible. I can’t get the arrow (.png) to display, it gets cut off by the height and I’m not sure how to get the height to show. I’ve tried several failed methods so far, hoping someone can help me out.
What I’ve done is style the anchor for the box and try to position the small arrow below the box. The arrow isn’t displaying outside of the box in the anchor, it gets cut off. I tried making the arrow the part of the LI, it worked but because the anchor needs to be 30px (height of the blue box) and the LI needs to be 40px (box + the height of the arrow 10px) it will display the arrow if you mouse over that 10px area and not the box.
currently it looks like this.
Here is my css:
#navlist {
float:right;
}
#navlist li {
line-height:40px;
display:inline;
list-style-type: none;
margin-right: 20px;
}
#navlist li:hover {
background:url(../img/navArrow.png) no-repeat center;
background-position:50% 30px;
}
#navlist li a {
height:30px;
padding:3px 5px 3px 5px;
color:#26627f;
}
#navlist li a:hover {
background:#035173;
border-radius:3px;
color:#fff;
}
and here is the html:
<ul id="navlist">
<li><a href="#">Get a Quote</a></li>
<li><a href="#">Learn about Life Insurance</a></li>
<li><a href="#">Our Company</a></li>
<li><a href="#">Get Help</a></li>
</ul>
You could simply add the following to your CSS:
JS Fiddle demo.
This does, of course, require that the user have a browser that implements CSS generated content and pseudo-elements.
Edited in response to comment from OP, in comments below:
It works because the border of an element meet at 45°, and because there’s no
height/widthfor the element that produces a triangular shape ‘pointing’ towards the centre of the element (or, in this case, the pseudo-element). If all four borders were visible you’d have a square; if top and bottom were visible you’d have a triangular ‘hourglass,’ and so on.To make the triangle smaller, simply assign a smaller unit to the border-width (in the example above the borders are set to
1em, simply change it to5pxor, well, any other size and unit of measurement that the browser can implement.The negative margin-left (the
-1emin themargindeclaration) has to be equal to theborder-widthin order to place the pseudo-element centrally along the horizontal axis, but it can be adjusted to taste.To add a
box-shadowis difficult, since all four borders have to be assigned to create the triangular shape, thebox-shadowwould be a rectangle for the whole element, not just the ‘visible’ part of it. It can be emulated, if you’re okay about using another pseudo-element, in this case the::before, but it won’t have the usual ‘fuzziness’ of a genuinebox-shadow, but, as a demonstration, simply copy the above CSS, amend the::afterto::before(and make sure the::beforeelement occurs before the declaration for::after, as the later-declared element will be above the previously-declared element). Adjust the margins and theborder-top-colorproperties and it should look okay-ish:JS Fiddle demo.