Como fazer uma seta elegante usando CSS?

Então, todos sabem que podes fazer um triângulo usando isto.
#triangle {
    width: 0;
    height: 0;
    border-left: 50px solid transparent;
    border-right: 50px solid transparent;
    border-bottom: 100px solid red;
}
E isso produz um sólido, cheio de triângulo. Mas como é que se faz um triângulo de tipo oco, como este?

an arrow with only two lines that intersect at the point. Like a greater than sign: >

Author: Bergi, 2014-12-15

10 answers

Pode usar o pseudo-elemento before ou after e aplicar-lhe algum CSS. Há várias maneiras. Você pode adicionar ambos before e after, e rodar e posicionar cada um deles para formar uma das barras. Uma solução mais fácil é adicionar dois contornos apenas ao elemento before e rodá-lo usando transform: rotate.

descer para uma solução diferente que usa um elemento real em vez dos elementos do pseuso

Neste caso, adicionei as setas como balas numa lista e ... usado em tamanhos para torná-los tamanho corretamente com o tipo de letra da lista.

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>

Claro que não precisas de usar before ou after, também podes aplicar o mesmo truque a um elemento normal. Para a lista acima é conveniente, porque você não precisa de marcação adicional. Mas às vezes você pode querer (ou precisar) a marcação de qualquer maneira. Você pode usar um div ou span para isso, e eu até já vi pessoas reciclar o elemento i para 'ícones'. Para que essa marca se pareça com a de baixo. Se usar <i> para isto é correcto é discutível, mas você pode usar o span para isso também para estar no lado seguro.

/* 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.

Se você procura mais inspiração, certifique-se de verificar esta incrível biblioteca de ícones puros CSS de Nicolas Gallagher. :)

 90
Author: GolezTrol, 2017-06-06 14:10:55
Isto pode ser resolvido muito mais facilmente do que as outras sugestões.

Basta desenhar um quadrado e aplicar uma propriedade border a apenas 2 lados.

Depois roda o quadrado de acordo com a direcção que queres que a seta aponte, para o 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>
 65
Author: Alan Dunning, 2017-04-30 14:49:17

Setas sensíveis

Eles dimensionam automaticamente com o seu texto e são coloridos da mesma cor. Plug and play :)
parque de demonstração jsBin

enter image description here

body{
  font-size: 25px; /* Change font and  see the magic! */
  color: #f07;     /* Change color and see the magic! */
} 

/* RESPONSIVE ARROWS */
[class^=arr-]{
  border:       solid currentColor;
  border-width: 0 .2em .2em 0;
  display:      inline-block;
  padding:      .20em;
}
.arr-right {transform:rotate(-45deg);  -webkit-transform:rotate(-45deg);}
.arr-left  {transform:rotate(135deg);  -webkit-transform:rotate(135deg);}
.arr-up    {transform:rotate(-135deg); -webkit-transform:rotate(-135deg);}
.arr-down  {transform:rotate(45deg);   -webkit-transform:rotate(45deg);}
This is <i class="arr-right"></i> .arr-right<br>
This is <i class="arr-left"></i> .arr-left<br>
This is <i class="arr-up"></i> .arr-up<br>
This is <i class="arr-down"></i> .arr-down
 36
Author: Roko C. Buljan, 2016-03-17 11:15:13
Eis uma abordagem diferente:

1) Usar o carácter de multiplicação: &times; ×

2) Esconder metade com overflow:hidden

3) em seguida, adicionar um triângulo como um pseudo elemento para a ponta.

A vantagem aqui é que não são necessárias transformações. (Vai funcionar em IE8+)

VIOLINO

.arrow {
  position: relative;
}
.arrow:before {
  content: '×';
  display: inline-block;
  position: absolute;
  font-size: 240px;
  font-weight: bold;
  font-family: verdana;
  width: 103px;
  height: 151px;
  overflow: hidden;
  line-height: 117px;
}
.arrow:after {
  content: '';
  display: inline-block;
  position: absolute;
  left: 101px;
  top: 51px;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 25px 0 25px 24px;
  border-color: transparent transparent transparent black;
}
<div class="arrow"></div>
 14
Author: Danield, 2014-12-16 09:13:52

Basta usar antes de e depois Pseudo-elementos - CSS

*{box-sizing: border-box; padding: 0; margin: 0}
:root{background: white; transition: background .3s ease-in-out}
:root:hover{background: red }
div{
  margin: 20px auto;
  width: 150px;
  height: 150px;
  position:relative
}

div:before, div:after{
  content: '';
  position: absolute;
  width: 75px;
  height: 20px;
  background: black;
  left: 40px
}

div:before{
  top: 45px;
  transform: rotateZ(45deg)
}

div:after{
  bottom: 45px;
  transform: rotateZ(-45deg)
}
<div/>
 11
Author: Gildas.Tambo, 2014-12-15 20:46:43

Uma outra abordagem utilizando fronteiras e no propriedades CSS3:

div, div:after{
    border-width: 80px 0 80px 80px;
    border-color: transparent transparent transparent #000;
    border-style:solid;
    position:relative;
}
div:after{
    content:'';
    position:absolute;
    left:-115px; top:-80px;
    border-left-color:#fff;
}
<div></div>
 8
Author: web-tiki, 2014-12-16 10:56:45

> é uma flecha maravilhosa! Prepara um mergulhador com ele e dá-lhe estilo.

div{
  font-size:50px;
}
div::before{
  content:">";
  font: 50px 'Consolas';
  font-weight:900;
}
<div class="arrowed">Hatz!</div>
 4
Author: nicael, 2014-12-16 14:39:33

Seta para a direita esquerda com efeito hover usando Roko C. Buljan box-shadow trick

.arr {
  display: inline-block;
  padding: 1.2em;
  box-shadow: 8px 8px 0 2px #777 inset;
}
.arr.left {
  transform: rotate(-45deg);
}
.arr.right {
  transform: rotate(135deg);
}
.arr:hover {
  box-shadow: 8px 8px 0 2px #000 inset
}
<div class="arr left"></div>
<div class="arr right"></div>
 2
Author: vinayakj, 2015-10-17 10:51:46
Precisava de mudar uma flecha no meu projecto. Abaixo está o trabalho final.

#in_submit {
  background-color: white;
  border-left: #B4C8E9;
  border-top: #B4C8E9;
  border-right: 3px solid black;
  border-bottom: 3px solid black;
  width: 15px;
  height: 15px;
  transform: rotate(-45deg);
  margin-top: 4px;
  margin-left: 4px;
  position: absolute;
  cursor: pointer;
}
<input id="in_submit" type="button" class="convert_btn">
Aqui.
 1
Author: Mostafa, 2015-09-24 16:44:41

.arrow {
  display : inline-block;
  font-size: 10px; /* adjust size */
  line-height: 1em; /* adjust vertical positioning */
  border: 3px solid #000000;
  border-left: transparent;
  border-bottom: transparent;
  width: 1em; /* use font-size to change overall size */
  height: 1em; /* use font-size to change overall size */
}

.arrow:before {
  content: "\00a0"; /* needed to hook line-height to "something" */
}

.arrow.left {
  margin-left: 0.5em;
  -webkit-transform: rotate(225deg);
  -moz-transform: rotate(225deg);
  -o-transform: rotate(225deg);
  -ms-transform: rotate(225deg);
  transform: rotate(225deg);
}

.arrow.right {
  margin-right: 0.5em;
  -webkit-transform: rotate(45deg);
  -moz-transform: rotate(45deg);
  -o-transform: rotate(45deg);
  -ms-transform: rotate(45deg);
  transform: rotate(45deg);
}

.arrow.top {
  line-height: 0.5em; /* use this to adjust vertical positioning */
  margin-left: 0.5em;
  margin-right: 0.5em;
  -webkit-transform: rotate(-45deg);
  -moz-transform: rotate(-45deg);
  -o-transform: rotate(-45deg);
  -ms-transform: rotate(-45deg);
  transform: rotate(-45deg);
}

.arrow.bottom {
  line-height: 2em;
  /* use this to adjust vertical positioning */
  margin-left: 0.5em;
  margin-right: 0.5em;
  -webkit-transform: rotate(135deg);
  -moz-transform: rotate(135deg);
  -o-transform: rotate(135deg);
  -ms-transform: rotate(135deg);
  transform: rotate(135deg);
}
<div>
  here are some arrows
  <div class='arrow left'></div> space
  <div class='arrow right'></div> space
  <div class='arrow top'></div> space
  <div class='arrow bottom'></div> space with proper spacing?
</div>

Semelhante ao Roko C, mas um pouco mais de controlo sobre o tamanho e a posição.

 0
Author: bob, 2016-09-21 19:20:22