简体   繁体   English

如何在链接(锚标记)旁边使用CSS添加插入符号(向下)?

[英]How do I add a caret (down wards) using CSS next to link (anchor tag)?

I want to add a caret symbol (down arrow or V) next to a menu item which has sub menu items. 我想在具有子菜单项的菜单项旁边添加一个插入符号(向下箭头或V)。 I know that it can be achieved using bootstrap. 我知道可以使用引导程序来实现。 But, I can't update my custom css with bootstrap css as it would become messy. 但是,我无法使用引导CSS更新自定义CSS,因为它会变得凌乱。

I'm happy to integrate only a part of bootstrap if that is going to work. 如果能够正常工作,我很高兴只集成一部分引导程序。

Please suggest me a solution asap. 请尽快给我建议解决方案。

You can try be using pure CSS to achieve a triangle: 您可以尝试使用纯CSS实现三角形:

Markup: 标记:

<div class="triangle"></div>

Style: 样式:

.triangle {
    width: 0; 
    height: 0; 
    border-left: 10px solid transparent;
    border-right: 10px solid transparent;

    border-top: 10px solid black;
}

As result, you have a solid down arrow that you can use. 如此一来,您将可以使用向下的实心箭头。 If you want to go beyond, you can override this property with another similar triangle over it and make an exactly caret in a "V" format: 如果您想超越此范围,则可以在该属性上覆盖另一个相似的三角形,并以“ V”格式进行完全插入记号:

Markup: 标记:

   <div class="triangle">
     <div class="over-triangle"></div>
   </div>

Style: 样式:

.triangle {
    width: 0; 
    height: 0; 
    border-left: 10px solid transparent;
    border-right: 10px solid transparent;
    border-top: 10px solid black;
}

.over-triangle {
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 5px solid white;
    position: relative;
    top: -10px;
    left: -5px;
}

This way you can get the exact form of a caret: 这样,您可以获得插入符的确切形式: 在此处输入图片说明

You can apply it to another element by making the triangle display: inline-table to align to the same line. 您可以通过display: inline-table三角形来将其应用于另一个元素display: inline-table以对齐同一行。

Now, it goes to you implement it on links! 现在,您可以在链接上实现它!

If you are looking for easy symbol intergrations, I would suggest font-awesome if you want to avoid bootstrap. 如果您正在寻找简单的符号集成,那么如果您想避免引导程序,我建议使用真字体。

http://fortawesome.github.io/Font-Awesome/ http://fortawesome.github.io/Font-Awesome/

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

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