Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have a requirement for allowing the users to select the web part header colors on a page. For example the home page of a site has an Announcements Web Part a Links Web Part, and a Calendar Web Part. Announcements should be green, links should be blue, and calendar should be orange. They want the ability to choose the color and my only thoughts are perhaps adding something to the edit menu of the web part or somehow getting the option to show in the advanced web part settings of all web parts. Should I even be thinking this is possible without some heavy dev?

The only other option I think I can give the group is that they just add a CEWP for the title and hide the web part header title.

share|improve this question

4 Answers 4

up vote 1 down vote accepted

As you want specific colors on multiple webpart headers on 1 page, that is not possible, even with javascript.

Why? Because all webparts have the exact same wrapping html/css, which makes it close to impossible to personalize/brand singular webparts.

From my point of view and experience you only have 2 ways of solving this (3 if you want to dance with the devil using javascript for this purpose).

  1. You create a pagelayout with multiple webpart zones places within various DIVs with classes, which you then in the CSS can use to narrow down your modifications - Example: .OrangeHeaders > ms-WPHeader, .OrangeHeaders > h3.ms-WPTitle { ... }
  2. Choosing this will make every webpart 100% customisable, but it will take time.
    You develop a new webpart for each webpart you want to be able to customize, inheriting the whatever webpart in question. Doing this will give you the opportunity to wrap each webpart in whatever CSS class you want and thus be able to fully customize it.
  3. (Dancing with the devil) - Using javascript. In the webparts header, you add prefixes - e.g. ORANGE Calendar. Then in your javascript you search for any ms-WPTitle which contains the text ORANGE (make sure it's case sensitive) and then add the color of the ms-WPHeader. Make sure to also include javascript code which hides the prefixes (by either hiding the text or removing it).

I personally always go with number 2 in case it's really necessary. 3 is some what plausable, but I would never recommend it, only suggest it.

share|improve this answer
    
Thanks for the input. Was thinking of giving the user a style sheet they can customize based off of the Title attribute for the headers. In the end they are fine with just using CEWP's to create the headers for now. A thought we did have was to create a custom web part that iterates through all the web parts on the page and writes out the titles to the web part. Leave the web part as only visible in edit mode. Next to each of the web part titles have a color picker/selector to allow them to choose colors. Then use the attribute css to apply it to the page. –  Cory Apr 30 '12 at 17:06
    
we started down the path of a custom web part, but then the client completely changed what they wanted, but thanks for the options –  Cory Sep 10 '12 at 13:35

The best option is probably to add some javascript (jQuery) to the page which loops through the Webpart headers and add style depening on title.

If the coloring is the same on all pages, then it's probably best to develop a delegate control (or change the masterpage), but otherwise it can be inserted using a CEWP (if you're nice you create a function in the masterpage so they only have to specify Title+Color)

share|improve this answer

This should work with moving webparts around the page. Also allows users to color both background and font color. Disables the coloring in edit mode so that users can read the titles easier. Point to your local copy of jQuery or CDN.

<script src="http://code.jquery.com/jquery-1.9.1.min.js">
</script>
<script>

var columnBGColor = ["red", "pink", "orange", "blue"];
var columnFontColor = ["white", "white", "black", "white"];
var columnIndex = 0;

function changeWPTitleColor(strWPTitle, strBGColor, strFontColor) {

 if($("a[title *= Close]").length == 0)
 { 
   var findTitle = $(".ms-WPTitle").find("span:contains('" + strWPTitle + "')");
   if(findTitle.length > 0)
   {
    findTitle.parents(".ms-WPHeader").css("background-color", strBGColor);
    findTitle.parents(".ms-WPTitle, .ms-WPTitle > A:link").css("color", strFontColor);
   }
 }
}

$(function() {

  var columnRows = $("td[name=_invisibleIfEmpty]");
  for(var i=0; i < columnRows.length; i++)
  {
    var column = columnRows[i];
    if($(column).is(":visible") && $(column).find(".ms-WPHeader").is(':visible'))
    {
      if($(column).find(".ms-WPHeader").children(":last").find("a[title *= Close]").length == 0)
      {
      $(column).find(".ms-WPHeader").css("background-color", columnBGColor[columnIndex]);
      $(column).find(".ms-WPTitle, .ms-WPTitle > A:link").css("color", columnFontColor[columnIndex]);
      columnIndex++;
      }
    }
  }

changeWPTitleColor("test", "grey", "blue");
 });

</script>
share|improve this answer

Its extremely easy. You can have multiple colors for different web parts in the same page. I have done it. All you need to know is their id. You can find their Id by using Mozilla firebug. Their id is always #MSOZoneCell_WebPartWPQ2 Only the number 2 changes to 3, 4, 5 for each web part. Here is how you change it.

  1. Open the site in SharePoint designer.

  2. Go to the master page (whichever you are using with that page like v4.master) and edit it

  3. In the <head> tag, add the following in a <style> tag

    #MSOZoneCell_WebPartWPQ2 .ms-WPHeaderTd { background-color:blue; }

    #MSOZoneCell_WebPartWPQ2 .ms-WPHeaderTd { background-color:red; }

Change the id as per your webpart id so that you can get different color for each web part header. Use mozilla firebug to find out the classes. Its extremely helpful. You can change the body color of each webparts differently too.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.