Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create Left Arrow with CSS before & after pseudo elements

I have created a right arrow.

How do I flip this to have a 2nd left arrow?

http://jsfiddle.net/n0rxtr48/

a {
    display: inline-block;
    font-family: Arial, Helvetica, sans-serif;
    font-weight: bold;
    padding: 10px 15px 10px 10px;
    position: relative;
    text-decoration: none;
}

a:before, a:after {
    border-right: 2px solid;
    content: '';
    display: block;
    height: 8px;
    margin-top: -6px;
    position: absolute;
    -moz-transform: rotate(135deg);
    -o-transform: rotate(135deg);
    -webkit-transform: rotate(135deg);
    transform: rotate(135deg);
    right: 10px;
    top: 50%;
    width: 0;
}

a:after {
    margin-top: -1px;
    -moz-transform: rotate(45deg);
    -o-transform: rotate(45deg);
    -webkit-transform: rotate(45deg);
    transform: rotate(45deg);
}

a:hover, a:focus,
a:hover:before, a:hover:after,
a:focus:before, a:focus:after {
    color: #000;
}
<a class="arrow"></a>
like image 266
michaelmcgurk Avatar asked Mar 13 '15 09:03

michaelmcgurk


3 Answers

You can rotate the arrow 180deg like this :

a {
    display: inline-block;
    font-family: Arial, Helvetica, sans-serif;
    font-weight: bold;
    padding: 10px 15px 10px 10px;
    position: relative;
    text-decoration: none;
}
.left{
  transform:rotate(180deg);
}

a:before, a:after {
    border-right: 2px solid;
    content: '';
    display: block;
    height: 8px;
    margin-top: -6px;
    position: absolute;
    transform: rotate(135deg);
    right: 10px;
    top: 50%;
    width: 0;
}

a:after {
    margin-top: -1px;
    transform: rotate(45deg);
}

a:hover, a:focus,
a:hover:before, a:hover:after,
a:focus:before, a:focus:after {
    color: #000;
}
<a class="arrow"></a>
<a class="arrow left"></a>

You can also achieve the same output with scaley(-1) instead of rotate.

Also there are way simpler ways to make this arrow, you might want to check this post with a great list of arrows like this one : How to Make A Fancy Arrow Using CSS?

like image 62
web-tiki Avatar answered Oct 21 '22 03:10

web-tiki


Tranform CSS property does not work with a lot of devices. I would suggest that you use Unicode symbols.

Here is a list of arrows : http://unicode-table.com/en/sets/arrows-symbols/

like image 41
Yann Avatar answered Oct 21 '22 02:10

Yann


alternatively you can use borders

:root{text-align: center}
a{width: 10px; height: 10px; position: relative}
a:before, a:after {
    color: black;
    border-right: 2px solid currentcolor;
    border-bottom: 2px solid currentcolor;
    content: '';
    position: absolute;
    width: 16px;
    height: 16px
}

a:before{
    left: -16px;
    transform: rotate(135deg)
}
a:after{
    right: -16px;
    transform: rotate(-45deg)
}
<a></a>
like image 35
Gildas.Tambo Avatar answered Oct 21 '22 03:10

Gildas.Tambo