Goal
A web part title bar with scripted rounded corners that can be displayed with or without a border.
Background
I wanted to create Sharepoint web part title bars with curved corners, and my search of the web led me to a couple of really good articles that got me started. Heather Solomon’s Post on Branding Sharepoint discusses how you can use gif files of the rounded corners to do this. I knew I did not want to use images since there are plenty of scripting solutions out there for creating rounded corners on the fly, but Heather’s post was invaluable in knowing which styles I would need to modify. As I am sure you have heard, Sharepoint is a horrible mix of tables, css styles, and inline styles, so it was great that someone had already waded through this problem and documented it.
I had been following Paul Grenier’s series about JQuery for Sharepoint at the EndUserSharepoint site, so I started searching for a way to do rounded corners with JQuery. I found a JQuery Plugin for Corner’s that is documented here.
I did not want to get into editing master pages, or creating custom style sheets for my solution, I wanted to keep it a simple solution that could be added on a page in a content editor web part, and would only affect the rendering of that page. Obviously, if you are interested in having curved web part corners on every page of your site, then you could adapt this solution for that. But for demo purposes, my solution has the following guidelines:
- The jquery script libraries are stored as two files in a document library on the site.
- A content editor web part contains a reference to the two script libraries.
- The content editor web part also has a couple of styles defined that override the styles inherited by the site
- The content editor web part has all of the scripts.
So, while this is not the best solution for a site wide change, it is perfect for testing and getting a feel for what you can do.
Solution
- Pick a document library on your site to store the two jquery library files. Upload these two files to the document library
- jquery-1.3.1.js – This is version 1.3.1 of the jquery.js library
- jquery.corner.js – This is a rounded corner plug-in for jquery.
- Edit the page you want the rounded corner’s to appear on, and add a Content Editor Webpart. Edit the web part, choose Source Editor, and paste the following code into the web part, without the line numbers. Be sure to adjust the line where the script libraries are referenced to point to the document library you used for step 1.
<style type="text/css">
.ms-WPHeader TD h3 {
margin: 0;
padding: 3px 0px 2px 5px;
height:24px;
}
.ms-HoverCellInActive {
margin: 0;
padding: 3px 0px 3px 0px;
height: 10px;
//}
.ms-WPBorder {
border-color: #85B2ED;
border-width: 1px;
}
</style>
<script type="text/javascript" src="<a href="http://site/Documents/jquery-1.3.1.js%22%3E%3C/script">http://site/Documents/jquery-1.3.1.js"></script</a>>
<script type="text/javascript" src="<a href="http://site/Documents/jquery.corner.js%22%3E%3C/script">http://site/Documents/jquery.corner.js"></script</a>>
<script type="text/javascript">
//Change these variables
var backColor = "#85B2ED"
var textColor = "white"
AddWebPartCorners();
function AddWebPartCorners(){
$(".ms-WPHeader TD h3").css("color",textColor);
$(".ms-WPHeader TD h3 a:link, .ms-WPHeader TD h3 a:visited").css("color",textColor);
$(".ms-WPHeader TD h3").css("background-color",backColor).corner("tl 7px");
$(".ms-WPHeader td").css("padding-right","0px");
$(".ms-WPHeader td").css("border-bottom","0px");
$(".ms-HoverCellInActive").css("background-color",backColor).corner("tr 7px");
}
</script>
How Does it Work?
Lines 1-20 provide overrides for a couple of styles that are set by Sharepoint in the Core.css file. There are 3 classes we are concerned with here, .ms-WPHeader TD h3, .ms-HoverCellInActive, and .ms-WPBorder.
| Web Part Title (.ms-WPHeader TD h3) | .ms-HoverCellInActive |
Above is a sample of the table that is used for the Web Part Header. It consists of one row and two columns. Here is an overview of each style.
- .ms-WPHeader TD h3 – This is the style for the the web part title column. I is I use it to hard code a height and control the padding. I tried finding a way around this, but, the problem is that the .ms-HoverCellInActive tag is a div, and from what I have researched, you can’t set the height of a div to fully fill a table cell unless that table cell has a height.
- .ms-HoverCellInActive – This is the style for the second column in the header. It is the portion of the web part where the menu selector is placed. It is also the place where we need to have the second rounded corner. Again, I am hard coding a height here, and setting the padding so that this div lines up with the first column.
- .ms-WPBorder – This is the style that controls the border of the content portion of the web part. I wanted to be able to match the border with the color I use for the web part title bar, so I just copied the style for it into here. You need to set this color manually to match whatever color you choose for the web part title bar.
- .ms-WPHeader td – This style is not labeled above, but it controls the style for each column in addition to the styles above. I am handling the styling of the .ms-WPHeader td with script, so it is not defined in the style section. But basically it is used to remove the bottom border of the web part title bar and more importantly to remove the right padding for the HoverCell. If this right padding is not removed, the web part title bar does not cleanly line up with the border on the right side.
Lines 22-23 add a reference to our two script libraries. Remember to point these to the location where you downloaded them. It could be a relevant site link, but for my purposes I didn’t want to have to change the line based on which level of the site it was placed at.
Lines 25-40 are where the actual rounding work is done. This is a script block.
Line 27 and 28 are variables used to hold the background color of the Webpart title bar and the text color. If you are using a dark background color you will most likely want to change the text color to a light color.
Line 30 is just a call to the function defined in Lines 32-38
As for the function, most of the code should be self-explanatory. Lines 33 and 34 just set the color of the text.
Line 35 sets the background color of the first column, and then calls the actual corner function of our library. Because this is the first column, I am only rounding the top-left corner (tl) with a radius of 7px.
In lines 36 and 37, I am changing the style for .ms-WPHeader td. This is used to remove the padding for the HoverCell column, and to remove the bottom border of both columns.
And finally, line 38 sets the background of the HoverCell column and rounds the top right corner of it
What I have and have not Tested
Working with stylesheets requires that you take into account different browsers that might access your site. In my case, this is an internal intranet site where the browser is controlled. So, I have only verified this with IE 7. I did test in Firefox, and it did not work, but Sharepoint has other problems with Firefox anyway. I have tested on both a MOSS site and a WSS team site. On a WSS team site, the Links web part does not appear to be styled the same as others, so I will have to research that further. There may be other web parts that do not use the same styles. If you run across others, let me know. I tested using the default theme, and also with a theme we had customized internally.
Where to go from here?
I’m not sure how much more work I will put into this, as it accomplishes the goal I set out to achieve. But others may want to build on this or may have a better way to handle the css. Jan Tielens has written a Feature for Sharepoint that will include the JQuery library for you (though I’m not sure that it will include the jquery.corner plugin), and I plan to investigate that. As stated above, Paul Grenier has a huge collection of cool things you can do with JQuery and Sharepoint. If you want to round the corners of the quick launch bar, there is an article at Share The Learning for that. I had a few problems getting it to work, but it was a great resource for this project. And finally, if you want to include any of this site wide, Heather Solomon is the place to go for customization tips.
Random Posts
Loading…
Looks great and exactly what I need but the only effect I can get it to produce is that it puts the rounded corners on the CEWP itself. No other web parts on the page are styled.
That’s strange. The most obvious thing to check would be to make sure the other web parts are set to display title or title and border in the web part properties.
Assuming that is not the problem, could you answer a few questions for me?
Which other web parts are you trying to display bars for?
Is this a MOSS site or just a WSS site?
If this is a MOSS site, is it a publishing site?
Are you using a built-in sharepoint theme that has not been modified? Which one?
If you add another content editor web part to the same page without any content, does the title bar display for it?
Hi,
I can’t able to see the rounded corners even i did the same as step 1 and 2.
javascript location in my site is as follows:
http://ukgrpwg-spdev01/sites/cssSite/subSiteTwo/Shared%20Documents/jquery.corner.js
http://ukgrpwg-spdev01/sites/cssSite/subSiteTwo/Shared%20Documents/jquery-1.3.1.js
Script i included in source editor is as follows:
.ms-WPHeader TD h3
{
margin: 0;
padding: 3px 0px 2px 5px;
height:24px;
}
.ms-HoverCellInActive
{
margin: 0;
padding: 3px 0px 3px 0px;
height: 10px;
}
.ms-WPBorder
{
border-color: #85B2ED;
border-width: 1px;
}
<script type=”text/javascript” src=”http://ukgrpwg-spdev01/sites/cssSite/subSiteTwo/Shared%20Documents/jquery.corner.js“></script>
<script type=”text/javascript” src=”http://ukgrpwg-spdev01/sites/cssSite/subSiteTwo/Shared%20Documents/jquery-1.3.1.js“></script>
var backColor = “#85B2ED”
var textColor = “white”
AddWebPartCorners();
function AddWebPartCorners()
{
$(”.ms-WPHeader TD h3″).css(”color”,textColor);
$(”.ms-WPHeader TD h3 a:link, .ms-WPHeader TD h3 a:visited”).css(”color”,textColor);
$(”.ms-WPHeader TD h3″).css(”background-color”,backColor).corner(”tl 7px”);
$(”.ms-WPHeader td”).css(”padding-right”,”0px”);
$(”.ms-WPHeader td”).css(”border-bottom”,”0px”);
$(”.ms-HoverCellInActive”).css(”background-color”,backColor).corner(”tr 7px”);
}
Am i doing any mistake.
Please reply.
Thanks,
Harini
Hi this is a great article. I’ve got a WSS site and a Publishing site will this only work for WSS? Also our network is on IE 6 (and I cannot get it to work), have you only tested this in IE7?
Thanks again!
Paula
It is working for me on a publishing site in MOSS. But yes, I have only tested on IE 7.
Just wanted to thank you and share a variant of your excellent function that I am testing (so far with success on Sharepoint 2007). I haven’t found a need for additional code or CSS tweaking yet.
function AddWebPartCorners(){
$(”.ms-WPHeader td:first-child”).css(”padding-right”,”0px”).corner(”tl”);
$(”.ms-WPHeader td:last-child”).css(”padding-right”,”0px”).corner(”tr”);
$(”.ms-HoverCellInActive”).corner(”tr”);
}
Evening
This is very nice, but I cannot get it working.
Iain
Anyone get this to work in MOSS and IE 6 or have any suggestions?
I couldn’t get it to produce any results.
After some fiddling I got this to work but I had to modify the two script lines. I am not sure what those two lines were originally trying to accomplish. However, I am having trouble with the spacing of the menu item. If I figure that out I will post that as well.
does not work … ahh well ..nice idea though .. perhaps showing us step by step what you did would be nice … although what you have typed here should be good enough also …
hi. has anyone done this for the top navigation bar as well?
I’m sorry it did not work for you. Maybe I will try to work on a better write up, however, I’m not sure how soon that will be. Do you get any part of it drawn?
worked fine for me. on the first try. there is an issue with firefox but like the article’s author mentioned, sharepoint got plenty issues with firefox as is.
Thank you for your response. I was beginning to wonder if anyone had gotten this to work besides me. I have to admin to this being somewhat of a hack, since I do not work with css and jquery on a daily basis. One of the problems with posting something that you do not fully understand is that people get frustrated when you cannot help them. I am not really using it in production, because what I really wanted was for a border to go all the way around and match up with the rounded corners of the title bar. This proved too difficult for me to solve.
It got worked for me, tested on IE 8. I’m facing one issue when i logged-in as a normal user (User has Read or ViewOnly premissions on the site), the right corner is not getting rounded because it will not appear for this user it is styled with ms-HoverCellInActive which will disappear.
How to make the right corner rounded even though logged-in user has Read or ViewOnly Permission on the site?
I think i’ve figured out why this isnt working for anyone.
” <– for some reason this quote is showing up in posts.
” <– sounds rediculous, but this is the quote you want. not the other one.
Hmm….it reformated my quote. Look, when you type out the code, dont cut and paste it from this site. Type it in character by character and the code will work. For some reason, this site is creating phony quotation marks. If you want to test it out, try copying one of the quotes from the comments into notepad (use courier new) and then type in a quote like you normally would. you’ll see what i mean.
<script type=”text/javascript” src=”http://site/Documents/jquery.corner.js“></script>
Not to mention that this syntax is awfully incorrect.
Thank you. Maybe that’s it. The code block plug-in I am using for Wordpress is a pain. Anyone out there got a favorite they use on their blog?
Thanks again. What should the syntax be?
I got this to work, thank you!
Question:
What if I just want to show the rounded corners for just a few webparts but not all of them? Thanks for your input!
I got this to work.. IE7 & IE8 but as what Ganapati Raibagi said if the account has only a viewer rights the right corner won’t turn into curve..
ANY IDEA HOW TO FIX THIS?
THANKS
How do you change a different web part title type? or extend to cover other items or classes? As I am getting some parts on the page that are working and others are not. For example in your screen shot you see just the edge of a web part that is not getting the settings that this is offering?
I love this look but it crashes IE for all our branch office users running IE 6. I REALLY would like to get this running for everyone. If a fix is found I would love to hear about it!
http://www.signaturesterling.com/blog/post/Rounded-Corner-Web-Parts.aspx