MOSS Forum

Ask Question   UnAnswered
Home » Forum » MOSS       RSS Feeds

Adding CSS to SharePoint 2007 custom webpart

  Asked By: Aaditya    Date: Feb 03    Category: MOSS    Views: 4289

I have created a custom webpart to takes the content from a list and
displays it within a table.

The webpart needs to have the background of the table set to a image on
a url and then custom colored font within the cells. I wanted to use
a .css file for this webpart and found some info on Google, but nothing
that will get me to a point where the webpart is displaying correctly.

Does anyone have source code they could share on how to put/call a .css
file from within a webpart and where should I store the *.css



1 Answer Found

Answer #1    Answered By: Graham Ingram     Answered On: Feb 03

It's actually relatively simple.

Create the .css file with you custom  style classes and put it into a directory
under the TEMPLATE\LAYOUTS directory of 12 hive.

Load it and apply it by using code similar to the following in the
CreateChildControls method of the web part.

Literal stylesheet = new Literal();
stylesheet.Text= "<BR><link rel=\"stylesheet\" type=\"text/css\"

Label NoStyle = new Label();
NoStyle.Text = "NoStyle";


Label Style = new Label();
Style.Text = "Style";
Style.CssClass = "CustomFont";

This sample code loads a stylesheet called Custom.css and applies a Font style
called CustomFont to a Label control. Another label control is left unstyled.

Didn't find what you were looking for? Find more on Adding CSS to SharePoint 2007 custom webpart Or get search suggestion and latest updates.