Adobe has some pretty cool header bars for modules on their site. The header bar is divided into left and right sections. The left being an explanatory title and the right being a related link. But let’s get super critical of how they did it.

First of all, they use a non-sprited image to do it:

That means an extra HTTP request just for the headers. Worse, the :hover effect is a totally separate image. That means yet another HTTP request and a “flash of black” while the second image loads on your first hover.
We can do it with zero images! Here’s our version:

The markup for the header is just a title with a link inside:
<div class="module">
<h2>Community <a href="#">Blue</a></h2>
<!-- stuff in module -->
</div>
Here’s the basic setup of the header, with the link on the right with basic coloring, including the straight white line made by a border:
.module h2 {
background: #ccc;
padding: 0 0 0 10px;
font-size: 16px;
/* Thickness of the bar more easily achieved with line-height
since padding would push link inward. */
line-height: 2;
}
.module h2 a {
float: right;
position: relative;
text-decoration: none;
color: #333;
padding: 0 10px;
border-left: 5px solid white;
}
Now the trick to getting the arrow within the line is just using CSS triangles applied via the ever-useful pseudo elements.

.module h2 a:before,
.module h2 a:after {
content: "";
position: absolute;
/* Pushed down half way, will get pulled back up half height of triangle
ensures centering if font-size or line-height changes */
top: 50%;
width: 0;
height: 0;
}
.module h2 a:before {
left: -12px;
/* Triangle */
border-top: 8px solid transparent;
border-bottom: 8px solid transparent;
border-right: 8px solid white;
/* Pull-up */
margin-top: -8px;
}
.module h2 a:after {
/* Smaller and different position triangle */
left: -5px;
border-top: 6px solid transparent;
border-bottom: 6px solid transparent;
border-right: 6px solid #a2d6eb;
margin-top: -6px;
}
One significant difference between ours and theirs is that they have a gradient that goes right through the triangle. That’s not possible with ours as it’s not practical to apply gradient with the CSS triangle technique. That’s not to say gradients are out though, you’d just need to make sure that where the triangle attaches to the main link, the color is solid.

For the demo page I added a few different colors, transitions, and examples where double-triangles could be used to fake an angled line.
Thank you sir you are doing a great job, I have seen your training on Lynda.com and you are a very good teacher. Thank you so much…
For newer browsers, you could use the transform property and rotate a square by 45 degrees. Although I suppose you’d need to make sure the square is positioned above the left header panel but below the right header panel with some z-index trickery.
yes – plus, you could do this with the :before and apply a border to it (or box-shadow with spread) and still have the :after to do something else with.
Make sure to put this in snippets!
Very nice – perfect for some breadcrumbs. I’ll need to check to see what our friend IE thinks of this.
very cool, thank you!
Two words, kick and ass…
Thank you…
I agree with your enthusiam Daniel, just not your addition.
Using the same concept, I recently added an arrow within a link/button. Works great … except I can’t get rid of a second 1px border on the transparent sides. Your demo has the same ghost border in my browser. Seems to be related to FF8 and the font color, I think.
Unfortunately I still haven’t found a solution.
Try changing the border style to “inset” on the transparent sides of the element.
See my comment below about
transparent
and how it’s the wrong value. Setting the border-style to “inset” is the wrong solution.You could rotate a pseudo element by 45deg and (i guess only in webkit) assign a diagonal gradient to it.
Very nice!
Two comments:
1) I see the same border Jeremy mentioned with FF 7
2) What does the above response have to do with this demo? Another damn SPAMMER! (Editor’s note: removed)
I have tweaked it a little so that the small triangle also contains a gradient. Tell me what you think, Chris
http://jsfiddle.net/PFWbs/
wow, that’s very impressive :(o)
Please don’t use
transparent
! People who use a Superior Browser (e.g. Firefox) which do antialiasing suffer, becausetransparent
isn’t what you meant. Remember thattransparent
is equivalent torgba(0,0,0,0)
(transparent black). Look at the demo page in Firefox and you’ll see why you need to not usetransparent
, but instead values likergba(255,255,255,0)
(transparent white).I don’t see a difference between “transparent” and rgba(255,255,255,0) in Firefox. What do you mean?
Ahh… I finally figure the antialiasing stuff. The black shadow has been annoying me for so long on Firefox.
Thanks a lot Chris!
@JK: it’s in the antialiasing. If you’re going from color X to no colour, you need the other side to be transparent X, not transparent black. It’s only along the diagonal edges that it will show. In an area of solid fill,
rgba(255,255,255,0)
will always look the same asrgba(0,0,0,0)
—transparent. One way to help you think about it is taking a larger gradient (the antialiasing is basically a gradient of up to 3px length) from#ccc
totransparent
and comparing it with a gradient from#ccc
torgba(204,204,204,0)
. The result is very different.In the demo as it stands the diagonal edges are very ugly in Firefox while they’re merely suboptimal in Chrome or IE (by dint of their not being antialiased).
I’ve almost finished a verbose blog post on the topic, I’ll try to remember to post a link here when I’ve started said blog and posted it.
Brilliant. That did the trick. Thanks
This is how the back button is styled in SenchaTouch. Confusing, but once you get the hang of it, makes perfect sense! Great article!
It’s great but I was just wondering… What font do you use for the part where it says the before and after pseudo element?
Great article Chris. I like all the extra stuff to be learned from reading the comments, like the FF anti–aliasing thing.
Enrique, the font looks like it’s Light up the World.
Great Article… Still confusing for me… but i will give it few more reads to understand the functionality at before and after…
Thanks !
Yeah, I’m still working on wrapping my mind around :before and :after. I think I just need to practice with some pseudo elements, rather than just read articles about them.
This one I just love! Great work!
Couldn’t you just add a 45-degree linear gradient to imitate any gradient that would occur in the middle section of the link, and have it line up once rotated? It would involve a bit of math, but otherwise, it seems a trivial solution to that problem.
use a picture , much easier , and you dont have to do so many brosers support.
but this is a great technique
Browser support for pseudo elements are excellent. IE6 & IE7 will not see the arrow but will have a sufficient fallback.
Using images means more http requests and longer loading times (yes, it will be tiny differences, but still).
So it comes down to what’s more important and appropriate for the current project, speed and resources or backwards compatibility.
That difference gets much bigger on a internet connection like mine, at 0.6 mbps.
@Ludwig: The demo page doesn’t degrade nicely on IE6 at all, the links end up below the banners and just generally things don’t look good. But if you’re designing for IE6, you know you’re facing some challenges. :-) Fortunately, most people don’t have to design for IE<8 anymore, and even big corporations and government departments are finally phasing in at least IE8 so even that niche will soon be free of the IE6/7 shackles. Designers for sites targeting China, though, look like still being stuck with them a while longer. But we’re nearly there!
this is realy nice tutorial thanx any body tell me bout best javascript book or tutorials website……thanx in advance
Wow! Awesome work. I feel very lucky for accidentally coming across your website today. Definitely won’t be the last time.
Greetings from Germany :)
These are great, thanks for the tutorial!
Such an amazing post. Thanks!
Nice touch. Added your site to my morning coffee list :)
As far as gradients go couldn’t you make the arrow transparent and the none arrow elements white then place it in a div with a background gradient? I’m looking into this myself, and really liked your example. Thanks
The following may not be as neat but it provides a gradient arrow. Is this any use to anyone?
FYI
The demo doesn’t work in IE8
( it’s sad but true)
I have to say, I truly dig this sort of stuff. @Paul does it fallback gracefully in IE8? I’d have to fire up a VM to check that out for sure but I’m certain that could be handled through conditionals, or maybe even employing Modernizer?
@Chris Morgan
You’re my hero! I was having the firefox anti aliasing issue when I was creating a CSS speech bubble. I couldn’t figure out for the life of me why firefox was adding extra lines. Using rgba(255,255,255,0) did the trick!