Trying to make arrow link with CSS. This one works in Firefox, but has a problems in IE and webkit-based browsers with arrowhead\'s position. Double div used for centering l
Try this code -- >
HTML :
<div>content</div>
<a href="#">Link</a>
<div>content</div>
CSS :
a{
padding:10px;
background:#2ecc71;
display:inline-block;
position:relative;
}
a:hover{
background:orange;
}
a:hover:after{
border-left: 20px solid orange;
}
a:after {
display: inline-block;
content: "";
width: 0;
height: 0;
border-top: 20px solid transparent;
border-bottom: 20px solid transparent;
border-left: 20px solid #2ecc71;
position: absolute;
right:-20px;
top:0;
}
JS FIDDLE DEMO
The border width and the right and top positions can be tweaked according to your needs
You should set the top
explicitly to 0
for the :after
element, and also remember to set the position:relative
for the div
element so that the absolute positioning works as expected:
.readmore > div::after {
...
top:0;
}
.readmore > div {
...
position:relative;
}
Fiddle
NOTE: The negative margin-top
should be removed. The cause of your problem is you use negative margin-top
(maybe by trial and error until it looks OK in FF), but the position also depends on the top
and left
. The default values of these properties are implemented differently by different browsers, the only solution to set it in order is explicitly set the top
, left
and remember the rule to determine the containing block for the absolute positioned element. (the nearest ancestor which has position as absolute
or relative
).