tags:

views:

34

answers:

2

I will be serving 3rd party content to other sites through an iframe. The content will be presented in a table. Is there any way to use internal style sheets where the defintions are defined within the iframe?? I have read that internal style sheets should only be defined in the head section. External css is not an option.

Here is an example of the content that would show inside the iframe.

    <STYLE TYPE="text/css">
    .className{
            background-color: #444444;
    }
    </STYLE>


    <table>
     <tr>
        <td class="className">
           Column 1.
        </td> 
        <td>
           Column 2.
        </td>
     </tr>
    </table>

Or is the only alternative to use inline css?

+1  A: 

that method there will work. tags are supposed to be used in the head of a document, but can appear in other places as well and be local to that branch of the DOM, including iframes

FatherStorm
Thanks. What I have read about using iframes outside of the <head> is that it can cause flicker. Will the flicker apply here?
M Schenkel
flicker can occur for a number of reasons. However, iframes should always be in th body of the containing document... not in the head.
quakkels
Oh - sorry. I phrased that statement totally wrong. I meant to say: What I have read about using internal css outside of the <head> is that it can cause flicker.
M Schenkel
+1  A: 

iframe content should be complete html/xhtml. What you have listed in your question will work but I can't see a reason not to have full html tags including <head>.


When you declare an iframe, you should belinking to a complete html file:

<iframe src ="myIframeContents.html">
  <p>Your browser does not support iframes.</p>
</iframe>

myIframeContents.html should be treated like any other html file. It should have tags for html, head, body, etc. This means that you can place <style> tags directly into the <head> just like you normally would.

myIframeContents.html:

<html>
    <head>
        <style type="text/css"> 
        .className{ 
            background-color: #444444; 
        } 
        </style> 
    </head>
    <body>
       <table> 
           <tr> 
              <td class="className"> 
                 Column 1. 
              </td>  
              <td> 
                 Column 2. 
              </td> 
           </tr> 
       </table>
    </body>
</html>
quakkels
You mean there would <head> section, and also even a <body> section?
M Schenkel
Yes... an Iframe should contain a complete HTML file. See edits in my answer.
quakkels