I have this following arrow in a layout, but I do not want to make an image but only with CSS. How do I do? do I have to use borders?
I have this following arrow in a layout, but I do not want to make an image but only with CSS. How do I do? do I have to use borders?
You can do with CSS with two shapes, a rectangle and a triangle. And so you can by whatever size you want from the arrow.
#triangle-right
{
width: 0;
height: 0;
border-top: 50px solid transparent; /* tamanho do topo ao meio */
border-left: 75px solid red; /* comprimeto da seta */
border-bottom: 50px solid transparent; /* tamanho do meio a baixo */
margin-left:100px; /* comprimento da cauda */
}
#rectangle
{
width: 100px; /* comprimento da cauda */
height: 50px; /* largura da cauda */
background: red;
position: absolute;
margin-top:25px; /* metade da largura para ficar centrado*/
}
<div>
<div id="rectangle"></div>
<div id="triangle-right"></div>
</div>
Using borders, you can improvise with CSS only, without needing any image:
.flecha::after {
display:block;
position:absolute;
content:'';
left:-26px;
top:-3px;
width: 20px;
height: 6px;
background:black;
}
.flecha {
position:relative;
margin-left:20px;
width: 0;
height: 0;
border-top: 6px solid transparent;
border-bottom: 6px solid transparent;
border-left: 6px solid black;
}
<div class="flecha"></div>
Edit: The logic is similar to that of @Jorge B.'s response, but does not need HTML changes, by using pseudo-elements instead of two DIVs sub>.
If the problem of having an image is the external resource, instead of linking the image, you can use a data URI :
.flecha {
width: 26px;
height: 12px;
background-repeat: no-repeat;
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABoAAAAMCAYAAAB8xa1IAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMy1jMDExIDY2LjE0NTY2MSwgMjAxMi8wMi8wNi0xNDo1NjoyNyAgICAgICAgIj4gPHJkZjpSREYg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RLPC3Dk0owWhuHOBgNJMxtGu6T/rU7tUOB3URQkgiB4hTIEANVY5kwa8l5JKSuOAbKHzCvkSEAMJ6OYiexyBfnK83zDIFre5uaO/Ae3C4tu3jClIzrZ4PlP+mNWkCkihLhfQS9Q2RmTGu5X0K8AAwD5DrixhRb2XAAAAABJRU5ErkJggg==);
}
<div class="flecha"></div>
Another alternative to this, even if it's not pure CSS, is to use webfonts icons like the link They are completely customizable in CSS (color, size, opacity, etc.).