Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to create arrow down/up in css

How can I create a arrow point down /up in css?

I tried to build it from div:

.triangle_down {
    width: 0;
    height: 0;
    border-left: 15px solid transparent;
    border-right: 15px solid transparent;
    border-top: 15px solid #2f2f2f;
    font-size: 0;
    line-height: 0;
    float: left;
}

This is the result:enter image description here.

But i tried to build something like this:enter image description here

Any suggestions?

like image 325
Maor Avitan Avatar asked Jan 06 '16 00:01

Maor Avitan


People also ask

How do you add up and down arrow in CSS?

Simply find the correct unicode characters you want. It won't matter which direction they're in, as you can just rotate them (like I did). Remember to set their display property to inline-block ! This is an arrow, he want's a chevron I believe.

How do you add a drop down arrow in HTML?

Use any element to open the dropdown menu, e.g. a <button>, <a> or <p> element. Use a container element (like <div>) to create the dropdown menu and add the dropdown links inside it. Wrap a <div> element around the button and the <div> to position the dropdown menu correctly with CSS.


4 Answers

My proposal is:

.triangle_down {
  width: 0;
  height: 0;
  border-left: 15px solid transparent;
  border-right: 15px solid transparent;
  border-top: 15px solid #2f2f2f;
  font-size: 0;
  line-height: 0;
  float: left;
}
.triangle_down1 {
  position: relative;
  top: -5px;
  content: "";
  display: inline-block;
  width: 15px;
  height: 15px;
  border-right: 0.2em solid black;
  border-top: 0.2em solid black;
  transform: rotate(135deg);
  margin-right: 0.5em;
  margin-left: 1.0em;
}
 .triangle_up1 {
   position: relative;
   top: -5px;
   content: "";
   display: inline-block;
   width: 15px;
   height: 15px;
   border-right: 0.2em solid black;
   border-top: 0.2em solid black;
   transform: rotate(-45deg);
   margin-right: 0.5em;
   margin-left: 1.0em;
 }
<div id="dialog1" class="triangle_down"></div>
<div id="dialog2" class="triangle_down1"></div>
<div id="dialog3" class="triangle_up1"></div>
like image 181
gaetanoM Avatar answered Oct 16 '22 15:10

gaetanoM


#uparrow:before {
    content: '\276F';
}

#downarrow:before {
    content: '\276E';
}

#uparrow, #downarrow {
    font-size: 30px;
    display: inline-block;
    -ms-transform: rotate(90deg);
    -webkit-transform: rotate(90deg);
    transform: rotate(90deg);
    padding: 10px;
}
<span id="uparrow"></span><span id="downarrow"></span>

You can include unicode characters like that, which are used by pretty much any system nowadays. Check out how it looks here: https://jsfiddle.net/mcdbu2pj/2/

Simply find the correct unicode characters you want. It won't matter which direction they're in, as you can just rotate them (like I did). Remember to set their display property to inline-block!

like image 39
MortenMoulder Avatar answered Oct 16 '22 14:10

MortenMoulder


If you don't want to use icons you can use ::before and ::after pseudo-class.

This is one of the various way you can get an arrow in pure CSS.

HTML

<div class="arrow"></div>

CSS

.arrow {
  position: absolute;
  top: 20px;
  left: 20px;
}

.arrow::before,
.arrow::after {
  position: relative;
  content: '';
  display: block;
  width: 20px;
  height: 1px;
  background: #000;
}

.arrow::before {
  transform: rotate(45deg);
}

.arrow::after {
  left: 14px;
  transform: rotate(-45deg);
}

You can find an example here: https://jsfiddle.net/f3qpujpL/2/

like image 6
fbid Avatar answered Oct 16 '22 13:10

fbid


What you want is a chevron, not an arrow. Pure CSS solution:

.chevron::before {
    border-style: solid;
    border-width: 0.15em 0.15em 0 0;
    content: '';
    display: inline-block;
    height: 0.45em;
    left: 0.15em;
    top: 0.15em;
    vertical-align: top;
    width: 0.45em;
    transform: rotate(135deg);
}

Check out this JSFiddle

like image 5
GAntoine Avatar answered Oct 16 '22 13:10

GAntoine