Question

Ofer Gal on Tue, 02 Oct 2012 14:53:50


In the master page I have:

      <SharePoint:CssLink runat="server" Version="4"/>

    <SharePoint:Theme runat="server"/>

    <!--loads our custom CSS AFTER corev4.css -->

    <SharePoint:CssRegistration name="/_Layouts/TheJointCommission/css/tjc.css" After="corev4.css" runat="server"/>

 

In a web part I render in  protected override void Render(HtmlTextWriter writer)

 

   writer.Write("<div id='Accreditation' > <table style='width:100%;' cellpadding='5px' cellspacing='5px'><tr><

etc…  this is static HTML I got from the designers, I copied their CSS to tjc.css  

The class 'mainContentTabContent' is in /_Layouts/TheJointCommission/css/tjc.css

When I examine the CSS with the IE dev tool, I expect everything within the <div id='Accreditation'  to be styled based on tjc.css but I see it is all inheriting from ms-WPBody which is in SharePoint’s corev4.css (did not change it and did not override the ms-WPBody class)

How can I force all the HTML inside the div to get the styling form tjc.css?

Replies

twagner320 on Tue, 02 Oct 2012 17:44:46


What are you specifically trying to force there can be a lot of different reasons for this. Looking breifly I would say it is because you are using a table inside the div try something like this:

writer.Write("<div id='Accreditation' > <table id='accredtable' style='width:100%;' cellpadding='5px' cellspacing='5px'><tr><");

table{

//default some styling here such as alignment, color

}

#accredtable{ //syling }

Ofer Gal on Tue, 02 Oct 2012 21:19:05


Since the HTML came from a static HTML file that showed right (but did not have a mention of corev4.css) I thought having the same CSS as the "after" should make it work.

I will try your Idea anyway. Thanks

twagner320 on Wed, 03 Oct 2012 03:29:14


Not all elements will inherit from the parent element by design. Table is one of those elements. Tables are intended to look different to set them appart from the rest of the text. If you put a table in the middle of a <p> element you would expect it to look different.

Ted Wagner SharePoint Architect