Q:

How to create triangle or caret icons using CSS

0

How to create triangle or caret icons using CSS

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Use transparent color for borders

You can easily create triangle or caret icons pointing up, down, left or right directions using the combination of transparent and solid colors for the borders of elements that doesn't have any CSS width and height. Let's check out an example to understand how it really works:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Creating Triangle or Caret Icons with CSS</title>
<style>
    /* Styles for border demo */
    .border-all {
        width: 0;
        height: 0;
        display: inline-block;
        border-width: 100px;
        border-style: solid;
        border-top-color: red;
        border-right-color: green;
        border-bottom-color: blue;
        border-left-color: orange;
    }
    /* Styles for caret icons */
    .caret {
        width: 0;
        height: 0;
        display: inline-block;
        border: 40px solid transparent;
    }
    .caret.down{
        border-top-color: black;
    }
    .caret.right{
        border-left-color: black;
    }
    .caret.up{
        border-bottom-color: black;
    }
    .caret.left{
        border-right-color: black;
    }
</style>
</head>
<body>
    <h2>Demonstration of How Borders are Applied on the Elements</h2>
    <div class="border-all"></div>
    <p>As you can see in the output above if we apply the transparent color on any three borders, the border remains with color will be displayed as triangle. Using that technique we can create our triangle or create icons, like this:</p>
    <h3>Triangle or Caret Icon Pointing Down</h3>
    <div><span class="caret down"></span></div>
    <hr>
    <h3>Triangle or Caret Icon Pointing Right</h3>
    <div><span class="caret right"></span></div>
    <hr>
    <h3>Triangle or Caret Icon Pointing Up</h3>
    <div><span class="caret up"></span></div>
    <hr>
    <h3>Triangle or Caret Icon Pointing Left</h3>
    <div><span class="caret left"></span></div>
</body>
</html> 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

HTML / CSS Frequently Asked Questions

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
How to remove outline around text input boxes in c... >>
<< How to truncate long string with ellipsis using CS...