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;
}
But i tried to build something like this:
Any suggestions?
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/
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>
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
#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
!
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
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);
}
Don't forget:
<div class="up"></div>
<div class="down"></div>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.