4

I was hoping someone may be able to guide me in the right direction. I want the header in a custom master page to have a background image that can be changed by an 'owner' in a user friendly manner.

The image(s) will be stored in a picture library on the root site and the master page is applied to all sites and sub-sites.

I had an idea whilst writing this post of using the logo URL option in the settings of the site.

Does anyone have any suggestions as to how I can achieve this?

Thanks in advance,
James

3
  • Thanks for the suggestions so far. Both idea's are great but are require a user editing a CSS file to apply a different banner. I was hoping to find a more user friendly or content manageable solution like the logo URL option in the settings of the site. Jun 27, 2012 at 15:30
  • Perhaps a custom solution that will manage a setting value and store it in the site property bag that I access within the master page like the site name etc. Jun 27, 2012 at 15:31
  • James, the solution I provided does not involve the user to modify anything in the css. Its a onetime filename entry by the designer and every subsequent updates can be made the owner. It means owner can upload the banner on the picture library and it appears on the masterpage automatically without any involvement of the designer or the owner to modify any css file. All it requires is the filename of the banner should be same as defined in the css style.
    – ArkoD
    Jun 28, 2012 at 10:53

4 Answers 4

2

Try this from this forum. http://social.technet.microsoft.com/Forums/en-US/sharepoint2010customization/thread/929c9fe6-a222-43a9-9551-985c0f20756d/

BODY
{
background-color:#F4F2E5;
background-image:url('../Style Library/Images/B360 Large.png')
}

OR

.s4-workspace
{
background-color:#F4F2E5;
background-image:url('../Style Library/Images/B360 Large.png')
}
0

You can probably use an alternate stylesheet with a class that calls the image from the picture library relative to its css file location. Best option would be to create a branding structure like this :-

/
/Style Library > YourProjectName > YourCssfile.css 
/Picture Library > OwnerUploadedImage.jpg

In your masterpage use the class on the td or div where you want to the background image to appear. On your css create the class with a style like background-image:url('../Picture Library/banner.jpg')

Ofcourse this will work once you have included the correct references to this stylesheet in the masterpage. From here on whenever an image with the same name and file extension is uploaded in the picture library by the owner it will appear in the masterpage. Only drawback is the solution is filename specific and you gotta hardcode your imagename in the css class.

0

I think this may be a good question. I've personally used the CSS method, similar to the other answers. You could do the Logo, like you wanted, from the site settings, but that creates an image tag as opposed to a background image. So the problem becomes how to change it from being an image into being a background. One thing you could try, then, is javascript. Use the javascript to get the "src" attribute from the logo image and then apply the image location to the "background-image" property of the header element. That is the least customization I can think of that still lets you set the background from the site settings.

  • Matt
0

I know it's been a few years, but I found a good solution to this. You have them insert a normal image into a containing div, and then you use this jquery:

$(function() {
    $(".header_image img").each(function(i, elem) {
      var img = $(elem);
      var div = $("<div />").css({
        background: "url(" + img.attr("src") + ") no-repeat",
        width: img.width() + "px",
        height: img.height() + "px"
      });

      div.addClass("replacedImage");

      img.replaceWith(div);
    });

});

$(function() {
$(".header_info").prependTo(".replacedImage");

});

The first function takes an image that's inside of my .header_image div and applies a bunch of css styles to it to make it a background image. Then it adds the class .replacedImage to it and then it changes the img tag to a div.

After this runs, the second function puts another div inside of that replaced image div (which in my case was .header_info).

So now anytime someone uploads an image to the ".header_image" div, it will turn it into a background image and wrap that div around my header info. Hope this helps anyone in the future! Here are the sources i've found that lead me to be able to do this:

Turn image src into background image: image src to background image

How to move an element into another element:move element

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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