Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create a round arrow with only HTML and CSS?

I'm trying to create a round directional arrow with CSS and HTML. Below are my attempts.

Attempt 1

In this I have rotated the <div> and an arrow, but both are in different positions.

This is the CSS:

 #curves div {     width: 100px;     height: 100px;     border: 5px solid #999;   }   #curves.width div {     border-color: transparent transparent transparent #999;   }   #curve1 {     -moz-border-radius: 50px 0 0 50px;     border-radius: 50px 0 0 50px;   }   .arrow-right {     width: 0;     height: 0;     border-top: 10px solid transparent;     border-bottom: 10px solid transparent;     border-left: 27px solid #ccc;     float: right;     margin-top: -7px;     margin-right: -26px;   }
<div id="curves" class="width">    <div id="curve1"></div><span class="arrow-right"></span>  </div>

Attempt 2

In this the arrow I have created is straight.

.container {    width: 60%;    height: 9px;    background: #ccc;    margin: 100px auto;    -moz-border-radius: 50px 0 0 50px;    border-radius: 50px 0 0 50px;  }  .arrow-right {    width: 0;    height: 0;    border-top: 10px solid transparent;    border-bottom: 10px solid transparent;    border-left: 27px solid #ccc;    float: right;    margin-top: -7px;    margin-right: -26px;  }
<div class="container">    </span><span class="arrow-right"></span>  </div>

Update I want it something like this

Enter image description here

like image 866
Manoj Dhiman Avatar asked May 05 '15 09:05

Manoj Dhiman


People also ask

How do you make an arrow in HTML and CSS?

Approach: Creating an arrow using CSS is very simple. First, create an L(alphabet) shape using some box-shadow property and then rotate it to some angle to align them (both left and right arrows) together. HTML Code: In this section, two div elements are created, one for each arrow.

How do I create an arrow shape in CSS?

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

How do you make a circle in HTML and CSS?

To create a circle we can set the border-radius on the element. This will create curved corners on the element. If we set it to 50% it will create a circle. If you set a different width and height we will get an oval instead.


2 Answers

You could use a pseudo element to generate the triangle (using the famous border hack).

After that, you would be able to use a thick border on the actual element (with a border-radius of 50% to make it a circle). This allows you to rotate the arrow to your liking.

div {    border: 20px solid transparent;    border-top-color: black;    border-left-color: black;    height: 100px;    width: 100px;    border-radius: 50%;    position: relative;    -webkit-transform: rotate(-45deg);    -ms-transform: rotate(-45deg);    transform: rotate(-45deg);    margin:30px auto;  }  div:before {    content: "";    position: absolute;    top: -20px;    left: 80%;    height: 0;    width: 0;    border-left: 30px solid black;    border-top: 30px solid transparent;    border-bottom: 30px solid transparent;    -webkit-transform: rotate(45deg);    -ms-transform: rotate(45deg);    transform: rotate(45deg);  }      /*BELOW IS FOR DEMO ONLY*/    div:hover {    -webkit-transform: rotate(315deg);    -ms-transform: rotate(315deg);    transform: rotate(315deg);    transition: all 0.8s;  }  html {    text-align:center;    color:white;    font-size:30px;    height: 100%;    background: rgb(79, 79, 79);    /* Old browsers */    background: -moz-radial-gradient(center, ellipse cover, rgba(79, 79, 79, 1) 0%, rgba(34, 34, 34, 1) 100%);    /* FF3.6+ */    background: -webkit-gradient(radial, center center, 0px, center center, 100%, color-stop(0%, rgba(79, 79, 79, 1)), color-stop(100%, rgba(34, 34, 34, 1)));    /* Chrome,Safari4+ */    background: -webkit-radial-gradient(center, ellipse cover, rgba(79, 79, 79, 1) 0%, rgba(34, 34, 34, 1) 100%);    /* Chrome10+,Safari5.1+ */    background: -o-radial-gradient(center, ellipse cover, rgba(79, 79, 79, 1) 0%, rgba(34, 34, 34, 1) 100%);    /* Opera 12+ */    background: -ms-radial-gradient(center, ellipse cover, rgba(79, 79, 79, 1) 0%, rgba(34, 34, 34, 1) 100%);    /* IE10+ */    background: radial-gradient(ellipse at center, rgba(79, 79, 79, 1) 0%, rgba(34, 34, 34, 1) 100%);    /* W3C */    filter: progid: DXImageTransform.Microsoft.gradient(startColorstr='#4f4f4f', endColorstr='#222222', GradientType=1);    /* IE6-9 fallback on horizontal gradient */  }
HOVER ME  <div></div>

If you then wanted to lengthen the arrow, you could make the bottom border visible. For example;

div {    border: 20px solid transparent;    border-top-color: black;    border-left-color: black;    border-bottom-color: black;    height: 100px;    width: 100px;    border-radius: 50%;    position: relative;    transform: rotate(-45deg);    margin:30px auto;  }  div:before {    content: "";    position: absolute;    top: -20px;    left: 80%;    height: 0;    width: 0;    border-left: 30px solid black;    border-top: 30px solid transparent;    border-bottom: 30px solid transparent;    transform: rotate(45deg);  }      /*BELOW IS FOR DEMO ONLY*/    div:hover {    transform: rotate(315deg);    transition: all 0.8s;  }  html {    text-align:center;    color:white;    font-size:30px;    height: 100%;    background: rgb(79, 79, 79);    /* Old browsers */    background: -moz-radial-gradient(center, ellipse cover, rgba(79, 79, 79, 1) 0%, rgba(34, 34, 34, 1) 100%);    /* FF3.6+ */    background: -webkit-gradient(radial, center center, 0px, center center, 100%, color-stop(0%, rgba(79, 79, 79, 1)), color-stop(100%, rgba(34, 34, 34, 1)));    /* Chrome,Safari4+ */    background: -webkit-radial-gradient(center, ellipse cover, rgba(79, 79, 79, 1) 0%, rgba(34, 34, 34, 1) 100%);    /* Chrome10+,Safari5.1+ */    background: -o-radial-gradient(center, ellipse cover, rgba(79, 79, 79, 1) 0%, rgba(34, 34, 34, 1) 100%);    /* Opera 12+ */    background: -ms-radial-gradient(center, ellipse cover, rgba(79, 79, 79, 1) 0%, rgba(34, 34, 34, 1) 100%);    /* IE10+ */    background: radial-gradient(ellipse at center, rgba(79, 79, 79, 1) 0%, rgba(34, 34, 34, 1) 100%);    /* W3C */    filter: progid: DXImageTransform.Microsoft.gradient(startColorstr='#4f4f4f', endColorstr='#222222', GradientType=1);    /* IE6-9 fallback on horizontal gradient */  }
HOVER ME  <div></div>
like image 129
jbutler483 Avatar answered Sep 21 '22 12:09

jbutler483


SVG solution

The shape is really simple to create in SVG.

For the svg interested:

<svg width="200px" height="200px" viewbox="0 0 400 400">    <path stroke="#000" stroke-width="50" fill="none"          d="M200 350 A 100 100 0 0 1 200 150             M200 150 200 125 225 150 200 175Z"/>  </svg>

Can i use it?

like image 30
Persijn Avatar answered Sep 20 '22 12:09

Persijn