2

Is it possible to set the background color of frames (I know, the assignment asks for it) using a single CSS instead of doing one for each frame. The assignment specifically asks for the use of CSS intead of tags. I have tried the following:

<frameset.........>
  <frame src="frames/leftframe.htm" class="LeftFrame" name="leftframe" noresize>
  <frame.......>
  <frame.......>
</frameset>

I have page called leftframe.htm, with:

<html>
  <link rel="stylesheet" type="text/css" href="../styles/allframes.css">
  <body>
    <p>..........</p>
  </body>
</html>

The style-sheet allframes.css has:

.LeftFrame
{
   background-color:#b0c4de;
}

I have not been able to get this to work. I am able to set the background-color per frame, as long as I have a separate style-sheet. If this is not possible I will just make separate style-sheets for each frame.

Linus Kleen
  • 33,871
  • 11
  • 91
  • 99
gestalt
  • 375
  • 3
  • 8
  • 25
  • 2
    Who on earth has you coding an assignment that involves frames? They are obsolete, and your time could be better spent almost anywhere else. – Tim M. Feb 23 '13 at 18:17
  • 2
    But +1 for trying, and I'm pretty sure you will need to reference the stylesheet in each frame for it to work...or do something like: http://stackoverflow.com/questions/217776/how-to-apply-css-to-iframe (should work for frames as well) – Tim M. Feb 23 '13 at 18:19
  • @TimMedora I tried that but I still don't get the background color, I tried adding allowtransparency="true" as some have said but it did nothing as well. – gestalt Feb 23 '13 at 18:28
  • 1
    I would simply use a shared stylesheet. There's no script needed and no duplicate CSS. – Tim M. Feb 23 '13 at 18:32

1 Answers1

2

The stylesheets of a frameset page cannot set the backgrounds of the pages it frames. It can set a background on the frame elements, but that’s a different issue: such a background would be seen only if the framed document had a transparent background. And in practice, not even then: the framed document will be displayed as if its ultimate background were white.

So what you can do is to set the background on the framed documents. You can use the same style sheet, but then you must not refer to anything that relates to the framing document, like the .leftFrame selector. You would simply write e.g.

body { background:#b0c4de; }

in a stylesheet that you link to from each of the framed document.

Jukka K. Korpela
  • 195,524
  • 37
  • 270
  • 390
  • OK, thanks. The only reason I asked is because I have to have different frames with different background colors and didn't want to do separate style sheets for each one. – gestalt Feb 23 '13 at 18:53