Thursday, May 14, 2009

Rounded Corners in SharePoint

Rounded corners have become a staple in website design. But they come with a price. Don't get me wrong I really like the look of them and they really help soften the look of the site.

In most cases you can create this look by using the method below. Later on in this post I will highlight some of the things you can do and some of the things not technically possible without major custom development.

Design 1: Rounded corners to frame a site:

  1. Open up your master page and add 1 <div> tag right before the ms-main table to represent the site container (This is used to position the site and give it its width)
  2. Add 4 more <div> tags before the ms-main table to represent your 4 corners (top left, top right, bottom left, bottom right)
  3. <div id="xyz-content-corner-tl">
    <div id="xyz-content-corner-tr">
    <div id="xyz-content-corner-bl">
    <div id="xyz-content-corner-br">
  4. Add in the following to CSS attributes to represent the 4 corners

background-image: url(/_layouts/images/xyz/xyz_content_corner_tl.gif);
background-position:left top;
background-repeat: no-repeat;
background-color: #ffffff;
background-image: url(/_layouts/images/xyz/xyz_content_corner_tr.gif);
background-position:right top;
background-repeat: no-repeat;
background-image: url(/_layouts/images/xyz/xyz_content_corner_bl.gif);
background-position:left bottom;
background-repeat: no-repeat;
height: 100%;
background-image: url(/_layouts/images/xyz/xyz_content_corner_br.gif);
background-position:right bottom;
background-repeat: no-repeat;
height: 100%;

Example: Please note that the shadow effect is a bit more complex and requires two more <div> tags to represent the right side repeat and the bottom repeat.


Design 2: Rounded corners to frame content

  1. This approach can achieved the same way as per above with 4 <div> tags but just needs to included around the <asp:ContentPlaceHolder id="PlaceHolderMain" runat="server"> control within the master page.



Design 3: Rounded corners around individual web parts

  1. Now this one has some tricky elements that I am still trying to work out.
  2. My Original thought was to use the approach above and simply add the 4 <div> tags around each individual webpart zone in a page layout. But there is a catch…
  3. Normally webpart zones are wrapped in a <td> that has an id of "_invisibleIfEmpty" There is some java script that basically hides that zone from rendering on the page if there is no content in it.
  4. However if you place those 4 div tags within that <td> you would assume that it would still hide that zone. But no basically its like a buffer and that JavaScript no longer thinks that zone is empty and it shows it on the page even if there is no webpart in that zone. So you end up with something like below: Notice that below the two web parts on the right there are two empty white containers with nothing in them.



So all in all its fairly easy to add in rounded corners to different areas within your design by using the approach above but there is still a need to have individual web parts with a container all for themselves.

If anyone out there has any ideas on either modifying the JavaScript to ignore the div tags and hide the empty zones or have any other approaches that have worked for them please don't hesitate to comment.



TK said...

Nice, now if only there was a corners pics gallery somewhere ... :)

Andy Burns said...

Damn, I was going to blog about that sometime soon! I did exactly what you did, and yes, had to do the web part zones, rather than web parts themselves.

Regarding the JavaScript - well, if you're dealing with publishing pages, I reckon it's good to 1) not use the out-of-box ones and 2) build your own.

If you end up doing 2), you can put your own javascript in instead. Personally, I'd be tempted to
- give the innermost div an attribute or name to find it by.
- do a bit of jQuery to find the innermost DIV, then call .parent().parent().parent().hide()

I'll maybe build a demo of that sometime.

Oh, and here were some of my other experiments into rounded corners...

Marcy Kellar said...

Erik, again, your expertise and experience really helps validate my direction.

We were using jquery for custom navigation and tried to use a plugin for rounded corners but found the stacking to be too troublesome. In fact, just today, I am revising our master page to include this method to create rounded corners in a custom design.

I hope we meet at SPC 2009 in Vegas. Are you speaking?

d3vlabs said...

when you are reffering to master page, can you specify exactly what file. im using wss 3.0 and have fubared my sharepoint installation once by editing the wrong master page. Thank you.

Brandon Michael Hunter said...

Does your solution scale based on screen resolution?

maxnmaria said...
This comment has been removed by the author.
maxnmaria said...

I apply the divs and CSS styles on frame content master page. The issues are it doesn't show the corners when you on edit page and othe system page i.e shared documents.It only display it properly on Home Page.