简体   繁体   English

如何在 css 中创建向下/向上箭头

[英]how to create arrow down/up in css

How can I create a arrow point down /up in css?如何在 css 中创建向下/向上箭头?

I tried to build it from div:我试图从 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?有什么建议么?

If you don't want to use icons you can use ::before and ::after pseudo-class. 如果您不想使用图标,可以使用:: before和::之后伪类。

This is one of the various way you can get an arrow in pure CSS. 这是您可以在纯CSS中获得箭头的各种方法之一。

HTML HTML

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

CSS 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/ 你可以在这里找到一个例子: 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: 纯CSS解决方案:

.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 看看这个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. 您可以包含类似的unicode字符,现在几乎所有系统都使用这些字符。 Check out how it looks here: https://jsfiddle.net/mcdbu2pj/2/ 看看它在这里的样子: https//jsfiddle.net/mcdbu2pj/2/

Simply find the correct unicode characters you want. 只需找到所需的正确unicode字符即可。 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 ! 请记住将其display属性设置为inline-block

Depending on the type of arrow you need, there is a very simple approach using HTML symbol codes.根据您需要的箭头类型,有一种使用 HTML 符号代码的非常简单的方法。 For instance I used &#x2191;例如,我使用&#x2191; for an arrow pointing upwards.一个向上的箭头。 I found it here HTML Symbols我在这里找到它HTML 符号

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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM