3

I know you can draw with a canvas element, I just wanted to know if it was possible to draw a triangle next to a link without using a canvas element? I just want a small < 16px down arrow.

1
  • 1
    My initial reaction is "no, CSS doesn't draw anything, it only styles, use an image background", but then I'm sure somebody would come along with some ingenious hack… :) Commented Nov 21, 2010 at 4:33

5 Answers 5

13

Here is my take on drawing a triangle in css. You can view it on JSFiddle. Have not done any browser testing (works in Chrome!)

The CSS is pretty simple:

.triangle{
display: block;
border-bottom: 16px solid transparent;
border-left: 16px solid red;
overflow: hidden;
position: absolute;
}

If you want it pointing in a different direction, just alter the borders. For example, the following will point the triangle downward:

.triangle{
display: block;
border: 16px solid transparent;
border-top: 16px solid red;
overflow: hidden;
position: absolute;
}

Edit: Works in latest IE, FF and Chrome.

Sign up to request clarification or add additional context in comments.

Comments

5

Nope.

The closest you could get is by using an ASCII key, &darr; to be precise.

It produces an arrow like this ↓

Of course a background-image will do the trick, but that's quite obvious, innit? :)

Comments

3

U+25BC: Black Down-Pointing Triangle exists in Unicode. Here it is: ▼

You could use this CSS to apply it:

a:before {
    content: "▼";
}

It's probably better to use a background-image though. That way, you would not depend on the existence of such special characters in the font the web browser uses, and it would show up in IE 6/7. For example:

a {
    background-image: url("arrow.gif");
    padding-left: 16px;
}

Comments

2

No. Just use a special ASCII character, &#darr;, no CSS required:

<span id = "down-arrow">&#darr;</span>

Comments

1

Here's my simple drawing for the triangle using CSS:

<div style="border: 11px solid transparent; border-right-color: rgba(0, 0, 0, 0.25);"></div>

If you need to change the direction, just replace border-right-color with border-direction-color. And maybe you use position: absolute; and margin-top and margin-left properties to set the position.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.