Google Analytics

Tuesday, October 5, 2010

Remove Default SharePoint Web Part CSS

**UPDATE: See this revision.

It’s always been a struggle for me to style a web part in SharePoint because of the default Microsoft classes that get added (i.e. .ms-WPBody a:link, .ms-WPBody a:visited, blah, blah, blah).  These stylings are annoying and difficult to override because they’re directly on the web part and sometimes replace general site CSS.
Well…just turn them off.

For the DataViewWebPart...
<SharePoint:DataFormWebPart runat=”server” NoDefaultStyle=”true” …>
</SharePoint:DataFormWebPart>
(This also works for the CoreResultsWebPart as it’s essentially just a DVWP).

If you're creating your own web part...
public class NoCssWebPart : WebPart
{
      public NoCssWebPart()
     {
          this.UseDefaultStyles = false;
     }
}

References:

1 comment:

  1. after 12 hours of trying to figure this out, THANK YOU!!!!

    ReplyDelete