in

SharePoint Blogs

The Best Place for SharePoint-related Blogs

Heather Solomon's Mirrored Blog

January 2008 - Posts

  • SharePoint 2007 Design Tip: Import your CSS for SharePoint Themes

    One of the major drawbacks of SharePoint themes is you have to reapply the theme to any site that uses your custom theme in order to see any new changes that you have made.  This happens because when you apply a theme to a SharePoint site, a copy of the theme is added for the site in the content database. 

    Try it out, open a test site in SharePoint Designer and look at the folder structure in the Folder List task pane.  If you have already applied a theme to this site, you will see a _theme folder. If you have not applied a theme to this site, then this folder will not appear.  Expand the folder and you will see a single sub folder named the same as your theme.  Now go and change the theme the site uses through a browser.  Return to SharePoint Designer and hit F5 to refresh the Folder List.   The _theme folder will appear if you didn't have a theme applied the first time, and the sub folder under this directory will change to reflect the theme you just applied.

    When you make a change to the theme files on the web server, it does not update any copies of the theme that live in the content database.  When you apply a new theme in the browser, it replaces the copy in the content database with a new theme.  That is why you have to physically reapply a theme when you make changes, you have to replace the theme copy in the content database.

    From a development perspective, the theme copy in the content database is rather handy.  If you update any of the files in the content database (by changing the CSS files in SharePoint Designer and importing in new images), the changes automatically appear in the browser. Woo-hoo! This just made life easier when it comes to developing themes.

    But after you finish up development, you are stuck back with the problem of how to update your theme in the future, especially if it is applied to several sites.  This is where this trick comes in.

    Import CSS to Create Editable Themes

    Create a copy of the final theme.css file and store it in another location on the web server, such as:
    C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS\1033\STYLES\YOURCUSTOMFOLDERHERE
    You can even rename the file, it no longer needs to be named theme.css.

    Open the original theme.css file in the custom theme folder, delete out all of the contents, and add an import rule for your new CSS file:
    @import "/_layouts/1033/styles/YOURCUSTOMFOLDERHERE/theme.css";

    Save the file and deploy your theme (add text to SPTHEMES.xml and reset IIS).   Apply your new theme to the site.  Now go to the new CSS file in the Styles folder and make a change.   Refresh your browser.  Your change will appear.  That is cool.

    By moving around your files and using the import rule  you can create a theme that you can update without reapplying the theme to every site that uses it.  Be sure to update your image paths in your CSS styles to a location where you can edit the images as well, such as:
    C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\IMAGES\YOURCUSTOMFOLDERHERE 

    Below are a couple of screen shots for the end result of this method.

    View of the file structure on the web server

    Image showing file structure on the web server

    View of the theme folder and the theme.css file that is still in the theme folder

    Image showing custom theme folder and custom theme.css file


  • DOCTYPES and SharePoint

    I got asked by two separate friends of mine just within a few days of each other if I had any recommendations for what DOCTYPE tag should be used in SharePoint.  Honestly up until that point, I had not put a lot of thought into outside of the attitude of look up whatever A List Apart recommends and use that.   So I delved into it a bit more and now I do have an opinion on the matter.

    A little info first, DOCTYPE is short for Document Type Declaration. A DOCTYPE associates a web page with a Document Type Definition (DTD).  The DTD is the definition of the particular version of HTML or XHTML you are using in your site and is what will be used for rendering of the web page.  For DTDs, there are generally 3 types, strict, transitional and frames.

    Strict means there isn't presentational elements in your code, such as formatting and alignment.  Instead everything has be to controlled separately in the CSS.   Transitional allows both CSS and presentational elements in the code.  Frames, well is for frames and if you are still using those we need to chat.   :-)

    Based on your DTD and what browser you are viewing your site in, your page will render in Standards mode or Quirks mode.  Standards mode renders the page based on the DTD you defined. Quirks mode will render the page the best it can while emulating older browsers.  If you don't define a DTD to use, the browser will default to Quirks mode. 

    So what about SharePoint?  First off, note that default.master does not specify a DTD! The publishing master pages (blueband, blackband, etc) use the HTML 4.0 Transitional DTD that renders in Standards mode.

    For my base master pages, I put in a DOCTYPE that uses the HTML 4.0 transitional DTD that will render the site in quirks mode.   Why?  It is the lowest common denominator and appropriate for the general use of the master page.  This is not to say this is the DTD you should be using for your site.  Ultimately, you need look at the site's target audience and purpose and select a DTD based on your individual site needs.

    However, I do think Transitional DTDs should be used since there is a lot of rendered code with out of the box SharePoint that you don't have control over, therefore your page will have presentation elements in the code and not solely use CSS for formatting.  That and Transitional is best when you use tables for page layout.   Tables vs. CSS positioning wars aside, out of the box SharePoint makes heavy use of tables for layout so stick with the transitional DTDs.

    I personally don't use the XHTML DTDs because I have yet to see justification for using them, and I get a bit worried about the fact that XHTML 1.0 won't be supported in XHTML 2.0 and vice versa.  It seems to me if you go with a XHTML DTD, you are limiting yourself.  But again, this goes back to what does your site need, not what makes me nervous.

    Another important thing about DTDs, is you need to select one BEFORE you delve too deep in developing your user interface.  The DTD you specify in the DOCTYPE tag will affect how your page is rendered, so don't write a bunch of HTML and CSS and then apply or change the DTD, many of your page elements could go out of whack and you will have to rewrite some of your code.

    Here are the two DTDs I think are best for SharePoint:

    HTML 4.0 Transitional in Standards Mode (use this one if you can):
    <!DOCTYPE html PUBLIC "-//W3C//DTD html 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

    HTML 4.0 Transitional in Quirks Mode:
    <!DOCTYPE html PUBLIC "-//W3C//DTD html 4.01 Transitional//EN">

    Here are some additional resources:

    UPDATE 1/25/08: Well DOCTYPES must be in the air, Waldek Mastykarz just posted about DOCTYPEs as well, and recommended the use of XHTML 1.0 Strict or Transitional DTD.  He talks about his reasonings and the benefits, drawbacks and challenges with this approach.  For a different viewpoint, read his article here.

  • UPDATED: Base Master Page - DOCTYPE

    I have updated my Base Master Pages again, this time changing or adding the DOCTYPE tag in each.  Please note that the base master pages include the HTML Transitional DTD that will display your site in quirks mode.  Please replace the DTD if you need a more refined presentation mode for your site.

    I selected this DTD because it can assist the broadest audience (older browsers, mobile views, newer browsers, etc).  If you want to use a standards compliant presentation mode, you can switch the DOCTYPE to:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

    or

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

    For more info about DOCTYPEs, check out the info at W3Schools.


Need SharePoint Training? Attend a SharePoint Bootcamp!

Posts (c) their respective authors. Everything else (c) 2007 SharePoint Experts