Reputation: 227
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;
}
<div class="triangle_down"></div>
But I tried to build something like this:
Any suggestions?
Upvotes: 14
Views: 41357
Reputation: 31
.arrow {
border: solid black;
border-width: 0 3px 3px 0;
display: inline-block;
padding: 3px;
}
.right {
transform: rotate(-45deg);
-webkit-transform: rotate(-45deg);
}
.left {
transform: rotate(135deg);
-webkit-transform: rotate(135deg);
}
.up {
transform: rotate(-135deg);
-webkit-transform: rotate(-135deg);
}
.down {
transform: rotate(45deg);
-webkit-transform: rotate(45deg);
}
<p>Right arrow: <i class="arrow right"></i></p>
<p>Left arrow: <i class="arrow left"></i></p>
<p>Up arrow: <i class="arrow up"></i></p>
<p>Down arrow: <i class="arrow down"></i></p>
Upvotes: 3
Reputation: 163
As simple as it gets:
.up,
.down {
content: "";
width: 10px;
height: 10px;
border: solid black;
border-width: 1px 1px 0 0;
}
.up {
transform: rotate(-45deg);
}
.down {
transform: rotate(135deg);
}
<div class="up"></div>
<div class="down"></div>
Upvotes: 2
Reputation: 426
Depending on the type of arrow you need, there is a very simple approach using HTML symbol codes. For instance I used ↑
for an arrow pointing upwards.
I found it here HTML Symbols
Upvotes: 0
Reputation: 6648
#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
!
Upvotes: 5
Reputation: 42044
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>
Upvotes: 13
Reputation: 1570
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/
Upvotes: 6
Reputation: 1275
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
Upvotes: 6