« Previous | Main | Next »

One pixel notched corners as used by Google Analytics

I use Google Analytics, and I noticed that their left nav has an interesting characteristic: instead of each option being boxed in a clickable rectangle, there is a one pixel notch in each corner. It's not necessarily a curved corner, but it is a little softer than a normal box.

Google Analytics Nav uses has a one pixel notch in each corner.

I would've naturally thought that if someone is going to use background images to create a capsule effect, they would have used anti-aliased images. But upon closer inspection, no background images were used at all. Instead, a couple of nested tags within the link help create the effect. Instead of this:

<ul>
  <li>
    <a href="/">
      Visitors
    </a>
  </li>
</ul>

Some <b> tags are added (likely chosen because because of their length - one letter):

<ul>
  <li>
    <a href="/">
      <b>
        <b>
          <b>
            Visitors
          </b>
        </b>
      </b>
    </a>
  </li>
</ul>

Now whether or not this is the purest thing to do is not the subject of this article. Obviously, I don't support overnesting of tags. But the Analytics designers did this for a specific design purpose. Nesting one tag is quite common for achieving sliding-doors rounded tabs. Perhaps the reasoning was, 'Why not nest two more and drop the use of images?'

Also, similar techniques exist out there to get rounded borders with a greater radius than just one pixel. However, those techniques involve much more extra markup (or javascript to create it for them) in the form of empty tags, where success comes in the form of a pixelated curve reminiscent of an 8-bit Nintendo display. (I exaggerate, but still.) In the case of a one pixel notch, the effect at least looks intentional.

The notched corner is created by modifying the nested tags' border and position properties.

Here's the CSS:

li a {
  display:block; /* a must */
  border: solid #666;
  border-width: 0 1px; /* left and right borders only */
  text-decoration: none;
  outline:none; /* so as not to distract from the effect */
  color: #000;
  background: #e4e4e4;
}
li a b {
  display: block; /* another must */
  position:relative; /* because the child elements are positioned */
  top: -1px; /* drag it up a little, creates the top notches */
  left: 0;
  border:solid #666;
  border-width:1px 0 0; /* top border only */
  font-weight:normal;
}
li a b b {
  border-width:0 0 1px; /* bottom border only */
  top: 2px; /* pushed down a little to create the bottom notches */
}
li a b b b { /* i don't think three-deep tag is even necessary */
  top:-1px;
  padding: 1px 6px;
  border-width: 0;
}

To just get the notch, the third-deep <b> tag isn't needed. I think Google Analytics included it because they wanted to add some background images with it on their buttons. I think this effect can be achieved with one less nested <b>.

<ul>
  <li>
    <a href="/">
      <b>
        <b>
          Visitors
        </b>
      </b>
    </a>
  </li>
</ul>

In my example page, I left it at two deep.

Comments (20)

Simon Käser said:

Nice technique there. But I don't see the need for more than one nested tag. One nested span tag is enough if you use negative margins rather than top and bottom.

example:
http://endlessx.com/rounded.html

Binny V A said:

IMO, using a background image is a much better way of creating rounded corners. Here's my implementation of rounded corners

Good technique. However, is there any way I can avoid nested tags.

I am an ASP.NET developer. And hence most of my controls are rendered the way the .NET framework decides. Though I can override, its too much work.

So, is there anyway I can pull it off by not using nested tags?

Thanks in advance,
SK

CSS Guy said:

@Simon,

Nice one - looks like a pretty safe method. Works in IE6 and 7, too. This makes me wonder even more about the reasoning behind the folks at Google Analytics using three nested <b> tags.

Why two b's? What's up with first-letter or first-line for a?

Rickibirder said:

Nice effect.

I've tried it as a feature div, as per your example page. Interestingly, in Firefox and Safari (haven't test IE yet) the contents of the box sit on top of adjacent suckerfish sub-menu items. I tried using Simon's technique (March 28) but any nested divs seem to create the same issue.

The div also flips out in IE, unless you put a width value to it and it seems to come good - so far.

Anonymous said:

What a great little trick!
Thanks

Barney said:

"This makes me wonder even more about the reasoning behind the folks at Google Analytics using three nested <b> tags."

Heehee. When did Google ever have a problem with generating a tonne of bloated deprecated markup to create universally unambiguous (to user agents, at least) layout? Take your DOM inspector to any Google widget and it's soup. They've always proved an authoritative case in point when arguing with standardistas — the case being for present browserland-unambiguous code as opposed to idealist W3 evangelism code.

Very good technique though. Thanks for running it past us!

@Sashidhar:
These don't need to be nested. To be extra safe it's best to put useless characters inside presentational tags (zero-width non-joiner [&#8204;] always works for me), but they can just all be lumped at the end (which is what I always do — that way you can easily just cut them out without mucking with your real content) as long as the overral parent is set to {position:relative}.

Matt said:

Is there a way to accomplish this same effect without the extra tags by using border attributes? Wouldn't something like

:link {border-length: 99%;}

do the job?

(Of course there's probably no border-length property, is there?)

CSS Guy said:

@Matt,

Sure, there are other ways of achieving the same effect - background images, tables (eek!), whatever. I just hadn't seen this one before.

Andrew said:

Nice one! It seems to be pretty rare I come across a method of doing something in CSS that I hadn't already seen, and this one fits the bill nicely.

@Simon
Nicely done! The more we can stay away from deprecated tags the better imho.

@CSSGuy,
Thanks for sharing!

@Simon
Way to take it a step further. I really like your method!

Arthur Lawry said:

*** I just noticed Simon's post with a similar solution using negative padding. This one uses absolute positioning so I'll post it as well ***

The example below is for 200-pixel wide options and includes a :hover effect:

<ul>
<li><a href="/"><span>Option 1</span></a></li>
<li><a href="/"><span>Option 2</span></a></li>
<li><a href="/"><span>Option 3</span></a></li>
<li><a href="/"><span>Option 4</span></a></li>
</ul>

ul {
width: 198px;
margin: 0;
padding: 0; }
ul li {
list-style: none;
height: 26px;
padding: 0;
margin: 0 0 2px 0; }
ul li a {
position: relative;
display: block;
background-color: #E4E4E4;
border-bottom: 1px solid #D7D7D7;
border-top: 1px solid #D7D7D7;
text-decoration: none;
color: #000;
height: 24px; }
ul li a span{
position: absolute;
display: block;
top: 0px;
left: -1px;
border-left: 1px solid #D7D7D7;
border-right: 1px solid #D7D7D7;
text-indent: 24px;
height: 24px;
line-height: 24px;
width: 198px;
font-size: 14px;
font-family: Arial, Helvetica, sans-serif; }
ul li a:hover {
background-color: #FFEAE0;
border-bottom: 1px solid #FFD3B4;
border-top: 1px solid #FFD3B4; }
ul li a:hover span{
border-left: 1px solid #FFD3B4;
border-right: 1px solid #FFD3B4; }

Kas said:

>The example below is for 200-pixel wide options and includes a :hover effect:

its no good. no work in IE6...

Michal Čaplygin said:

Nice.
I've made a simple test case using two nested elements and negative margin, as proposed in the first comment. 'Core' came up like this (ems used just for fun):


.softener-outer {
border-width: 0.3em 0;
margin: 0 0.3em;
}
.softener-inner {
border-width: 0 0.3em;
margin: 0 -0.3em;
}

I am quite surprised how simple it is : )

Derive Host said:

Many Thanks for Sharing.

Best Regards
Team
Web Hosting Sri Lanka

Hi from puerto vallarta jalisco mexico, please visit: www.saboravallarta.com.mx News Radio & Television Online
thanks !!!

f-bomb said:

Nice tutorial, but this is highly impractical. I can't see any benefit for using so much CSS to replace a small image. Why waste the time only to be challenged with cross-browser compatibility?

Ryan said:

Nice article - I am re-coding my website and will use this method. I have not seen this before - Thumbs Up!

rg

Neil said:

To be honest, i have analytics installed on my site but they are always giving me the wrong info ;( Not a fan anymore

Post a comment

If you want to show tags, use &lt; and &gt; for < and >, respectively.

Ask the CSS Guy

About this site.

Send questions, including links or code, to askthecssguy@gmail.com.

Subscribe to this blog's feed.

About

This page contains a single entry from the blog posted on March 28, 2008 3:09 PM.

The previous post in this blog was New CSS Off Contest April 5.

The next post in this blog is Can deprecated tags become undeprecated?.

Many more can be found on the main index page or by looking through the archives.