Ok, so everyone knows you can make a triangle using this:
#triangle { width: 0; height: 0; border-left: 50px solid transparent; border-right: 50px solid transparent; border-bottom: 100px solid red; }
And that produces a solid, filled in triangle. But how would you make a hollow-type arrow-like triangle, like this?
Arrows. To create a simple arrow without a tail, make a box with a width and height, border, as well as zero left and top borders. To make an up arrow, add the transform: rotate(225deg); property, and to make a down arrow, add the transform: rotate(45deg); property to rotate the arrow to 225 and 45 degrees respectively ...
<i class="icon-chevron-down"></i>
You can use the before
or after
pseudo-element and apply some CSS to it. There are various ways. You can add both before
and after
, and rotate and position each of them to form one of the bars. An easier solution is adding two borders to just the before
element and rotate it using transform: rotate
.
Scroll down for a different solution that uses an actual element instead of the pseuso elements
In this case, I've added the arrows as bullets in a list and used em
sizes to make them size properly with the font of the list.
ul { list-style: none; } ul.big { list-style: none; font-size: 300% } li::before { position: relative; /* top: 3pt; Uncomment this to lower the icons as requested in comments*/ content: ""; display: inline-block; /* By using an em scale, the arrows will size with the font */ width: 0.4em; height: 0.4em; border-right: 0.2em solid black; border-top: 0.2em solid black; transform: rotate(45deg); margin-right: 0.5em; } /* Change color */ li:hover { color: red; /* For the text */ } li:hover::before { border-color: red; /* For the arrow (which is a border) */ }
<ul> <li>Item1</li> <li>Item2</li> <li>Item3</li> <li>Item4</li> </ul> <ul class="big"> <li>Item1</li> <li>Item2</li> <li>Item3</li> <li>Item4</li> </ul>
Of course you don't need to use before
or after
, you can apply the same trick to a normal element as well. For the list above it is convenient, because you don't need additional markup. But sometimes you may want (or need) the markup anyway. You can use a div
or span
for that, and I've even seen people even recycle the i
element for 'icons'. So that markup could look like below. Whether using <i>
for this is right is debatable, but you can use span for this as well to be on the safe side.
/* Default icon formatting */ i { display: inline-block; font-style: normal; position: relative; } /* Additional formatting for arrow icon */ i.arrow { /* top: 2pt; Uncomment this to lower the icons as requested in comments*/ width: 0.4em; height: 0.4em; border-right: 0.2em solid black; border-top: 0.2em solid black; transform: rotate(45deg); }
And so you can have an <i class="arrow" title="arrow icon"></i> in your text. This arrow is <i class="arrow" title="arrow icon"></i> used to be deliberately lowered slightly on request. I removed that for the general public <i class="arrow" title="arrow icon"></i> but you can uncomment the line with 'top' <i class="arrow" title="arrow icon"></i> to restore that effect.
If you seek more inspiration, make sure to check out this awesome library of pure CSS icons by Nicolas Gallagher. :)
This can be solved much easier than the other suggestions.
Simply draw a square and apply a border
property to just 2 joining sides.
Then rotate the square according to the direction you want the arrow to point, for exaple: transform: rotate(<your degree here>)
.triangle { border-right: 10px solid; border-bottom: 10px solid; height: 30px; width: 30px; transform: rotate(-45deg); }
<div class="triangle"></div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With