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:.
But i tried to build something like this:
Any suggestions?
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.
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.
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>
#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
!
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/
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
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