PatientsLikeMe Tech Blog

We’re a team of Ruby on Rails developers and UX practitioners at PatientsLikeMe, where patients share data about their treatments, symptoms, and disease outcomes. We’re classically trained ninjas, pirates, rockstars, and dinosaur hunters. Our keyboards are magic wands — with lots of buttons, so they’re even better than regular magic wands. Meet the Team ↓

Using Borders to Make Pure CSS Arrows

In between creating awesome for PatientsLikeMe, Jeffrey and I built an app based on the Dribbble API called Liiikes. If you want to know more about Liiikes, you can check out the About page, my blog post, or Jeffrey’s announcing it. Today, we’re gonna talk about just one little design element.

Specifically, I want to talk about the arrow on this popup:

Liiikes Popup

What I wanted to solve:

I happened to find this tutorial on making pure CSS triangles using borders. I thought, “oh snap, this could work!”

Basically, borders render like this:

Yippee!

If you suppress the content area, you suddenly get this:

You seeing what I’m seeing? Now make 3 of those borders transparent!

Blizzam! Now all you have to do is absolutely position it to align nicely with your popup, or whatever you’re attaching the arrow to.

For the Liiikes example, here’s the HTML. In this case, I used an empty div. If that makes you uncomfortable, I’m sure you can apply it to another element somewhere. You’re a smart kid.

<div class="arrow"></div>
And here’s the good stuff:
div.arrow { 
  position: absolute; 
  top: 20px; 
  left: -40px; 
  border-top: 20px solid transparent; 
  border-bottom: 20px solid transparent; 
  border-right: 20px solid rgba(0,0,0,.85); 
  border-left: 20px solid transparent; 
}

Enjoy!

5 Comments

  1. On November 9th, 2010 at 12:24 pm Danny Chapman said:

    Awesome idea! Love this.

  2. On November 9th, 2010 at 12:31 pm Adam Darowski said:

    Nah, you just love seeing your name in the screenshot. ;)

  3. On November 9th, 2010 at 1:02 pm Matthew Anderson said:

    Fabulous! Thanks for sharing, Adam!

  4. On November 9th, 2010 at 2:12 pm Tweets that mention Using Borders to Make Pure CSS Arrows | PatientsLikeMe Tech Blog -- Topsy.com said:

    [...] This post was mentioned on Twitter by Adam Darowski, Jeremy W ヽ(`Д´)ノ. Jeremy W ヽ(`Д´)ノ said: RT @adarowski: super quick blog post on the @patientslikeme Tech Blog called "Using Borders to Make Pure CSS Arrows". http://bit.ly/91w0YZ [...]

  5. On November 10th, 2010 at 10:19 am Joe Alba said:

    Just plain clever. Nice work, man.