Ask the CSS Guy

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 (47)

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

Sashidhar Kokku said:

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.

Webstandard-Team said:

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.

Stewart Schatz said:

@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

Saboravallarta said:

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

Francisco Aquino said:

I wrote this and noticed someone used the same idea, but will post it anyway since it uses the simplest HTML structure and complete cross-browserness we all love.

ul
{
    padding: 0;
}

a, li
{
height: 25px;
line-height: 25px;
width: 240px;
border: solid 1px #aaa;
}

li
{
list-style: none;
border-top: 0;
border-bottom: 0;
margin: 0 0 4px 0;
background: #eee;
position: relative;
}

a
{
position: absolute;
top: -1px;
border-left: 0;
border-right: 0;
width: 100%;
}



T-Shirt Girl said:

wow thanks for this great "trick", but I wonder if the work is really worth it instead of just using a bg-image...
Léonie.

Anti said:

I'm sorry, but this is terrible. I'm not a standards zealot, but seeing atrocious markup like this being rah-rah'd makes them look pretty sane.

Think about it people, you're using two dozen lines and utterly non-semantic markup to achieve a presentational effect that is *already available in most browsers with a single line of CSS*.

Just use border-radius: 1px and let the UAs that don't understand it (which includes IE and only IE) ignore it and get flat borders.


Squirrel said:

Anti - border-radius is a cool idea, but for those of us who code in the real world we can't use CSS3 standards, we have to code for crap like IE 6 because 90% of companies still use it unfortunately.

JT... said:

Nice code from @Simon there...
Although I did change the span to a b tag. I'm kooky like that.

Colin Miller - Freelance web designer said:

Nice technique, I like it! subtle.

Oh by the way you might not be aware but you are getting an error on this page...

Error: jQuery is not defined
Source File: http://quarterlife.com/commons/javascript/dimensions.js
Line: 1

Joost vd Wal said:

I try to avoid nesting empty tags if possible.
Thanks Simon, for the example with negative margins.
I've modified it to drop the empty tags.. tradeoff being no IE6 border highlight on hover. For lack of a better defense, lets call that graceful degradation ;)


ul {
width:180px;
list-style-type:none;
margin:0 auto;
padding:0;
}
li, li a {
display:block;
position:relative;
border:1px #ccc solid;
}
li {
border-width:1px 0;
margin:4px 1px;
}
li a {
border-width:0 1px;
margin:0 -1px;
padding:2px 6px;
background-color:#eee;
text-decoration:none;
color:#555;
}
li a:hover {
background-color:#ddd;
}
li > a:hover, li:hover {
border-color:#aaa;
}

Links will be simple li a's

<ul>
<li><a href="#">Testlink</a></li>
<li><a href="#"> Testlink</a></li>
<li><a href="#"> Testlink</a></li>
</ul>

Joost vd Wal said:

Same thing, but with variable widths and possibility to float (if you want buttons)


ul {
list-style-type:none;
padding:0;
}
li, li a {
display:block;
position:relative;
border:1px #ccc solid;
float:left;
}
li {
border-width:1px 0;
margin:4px;
}
li a {
border-width:0 1px;
margin:0 -1px;
padding:0.3em 0.5em;
background-color:#eee;
text-decoration:none;
color:#555;
}
li a:hover {
background-color:#ddd;
}
li > a:hover, li:hover {
border-color:#aaa;
}


<ul>
<li><a href="#">Testlink</a></li>
<li><a href="#"> Testlink with more text</a></li>
<li><a href="#"> Testlink</a></li>
</ul>

Jesper Rønn-Jensen said:

The B-tag mod was also done by Erik Meyer and Tantek when designing Technorati.

Tantek explains in the comments about the considerations on my blog in this article:

Rounded Corners the Technorati Way (Feb 2007)

BTW, i did a small JQuery script that adds the round corners automatically -- just add a css class="round"

JQuery Rounded Corners (Technorati Style) (May 2008)

Control Panel said:

I would like to know how to round corners as in google ads. Can you please let me know?

Kevin Jansz said:

The third level b is for padding. The -1 is putting it in the center again.

Setting a padding at any of the other levels would push the borders out.

Masim man said:

Hi guys, thanks for sharing...

I like to learn something that I don't know before, just like this one. I will try this nice tip and also the other commenter tips as well. Another method of rounded corner I have done with my blog theme, simple and resizable.

But I would like to know how it looks like in other browser, I only tested it in new version of Opera, Safari, IE, and Firefox.

Again, thanks to you all.

Greg Millard said:

You are soooo stupid!
Just use background images!
Or better yet, Mozilla Firefox's -moz-border-radius:5px; which is anti-aliased, and is what all the smart web designers use.

Web Design Forum said:

I've seen the 1px less each line method used on sites, and have used it myself and it works ok. If you make each line on the top of your menu a different shade of the colour you've chosen, you get quite a good smooth tube effect.

dora said:

Thanks for the tutorial. Here is the easiest way to generate round corner: http://www.roundz.net

Chow said:

The simple reason to nest one more B, is that you can use the B alone just for ...aham... BOLD. If you put a little dot on the first B, you loose the B's main functionality.

Tim Sheiner said:

For purely notched corners, this technique can be simplified further. Just use a single 'b' object with both a top and bottom border. Adjust the height and width of that object to create the appropriate 'extra' borders.

Jack Motal said:

interesting use of css that google uses

Rik Weber said:

Nice trick, though a little long winded way of doing it by Google.

To be honest I'm not a major fan of these kind of methods as they go against the whole idea of separating code and design.

Still stuck in my old ways of background images I guess :)

Emil said:

Hi,

I've downloaded your roundBox I would say like month ago, however I think that something is going wrong. Where can I get the instructions or sample please.

Thanks,
Emil

Nils Hendriks said:

@ Greg Millard

What a dumb comment.

'border-radius' is part of CSS Backgrounds and Borders Module Level 3 which is still a working draft. So it will not validate when you use either -moz-border-radius or webkits version.

I think this is the very reason "all smart" web developers stay away from it for now.

If you comment, say something useful or just don't and prevent yourself from coming across as a jerk and dumb @ss.

Saboravallarta said:

Bienvenido a mi sitio de enlace los invito a visitar www.saboravallarta.com.mx Noticias Radio y Television Online desde Puerto Vallarta Jalisco Mexico, Transmitimos Musica, Entrevistas, Reportajes, Eventos Deportivos Mundiales, Nacionales, y Locales, visitanos y disfruta de nuestra programacion !!

Saludos !!

System admin and web design said:

Very nice! I was having trouble making my dom "buttons" lokk the same in IE and FF. This works and looks good!

Janice Ann said:

Well, how about http://theboxes.paradise.sg ? Seems neat. Way too easy.

Saboravallarta said:

Saboravallarta

Bienvenido a mi sitio de enlace los invito a visitar: http://www.saboravallarta.com.mx Noticias Radio y Television Online desde Puerto Vallarta Jalisco Mexico, Transmitimos Musica, Entrevistas, Reportajes, Eventos Deportivos Mundiales, Nacionales, y Locales, visitanos y disfruta de nuestra programacion !!

Saludos !!

nik said:

      <b>
        <b>
          <b>
sad, really sad. All this mess for such a little effect.

Extend Studio said:

You can also create rounded corner CSS boxes in Dreamweaver without coding or image manipulations using FlexiPanels CSS

 

Post a comment