How to add a flash background to an html element

Tuesday 27 January 09 by Onsitus in CSS Tutorials

Thanks to the css property z-index, we can easily add a flash background (swf) to an html element.

The basic steps to add an swf as background are…

To the div container which holds both swf then the other html element:

  • the width and height of the main div container
  • the position:relative; to allow to position the swf in a absolute mode in relation to its container

For the element which contains the swf:

  • an inferior z-index so to keep the swf underneath the other element
  • a position:absolute; to remove it from the normal flux of the page and position on top of it the other html elements

For the element which contains the html content to add at the top:

  • a superior z-index so to keep the html content above the swf
  • a position:relative; to position it in relation to its div container

For the swf itself:

  • Publish it with a transparent background from flash to obtain the right script or manually edit the html to add the parameter wmode with the value transparent

Basic html structure:

<div id="container">
<div id="background">
Add here the details to embed swf
</div>
<div id="content">
Add here the html content
</div>
</div>

The basic css rules:

#container{
height: 400px;
width: 500px;
position: relative;
}
#background{
z-index: 1;
position: absolute;
}
#content{
z-index: 2;
position: relative;
}

In the following example, I used a swf with a snow effect and added above it a title h2.

The result:


HTML ELEMENT ABOVE A FLASH ELEMENT

NB: due to a bug with the flash player, the above method is not valid for Linux users

8 comments

Stay updated with our RSS Feed

{ 2 trackbacks }

z-index: changing the stacking order of elements
02.09.09 at 10:48
Flash i
12.15.09 at 11:46

{ 6 comments… read them below or add one }

Rudy Bachrudin 07.25.09 at 18:16

Very well… nice tips…. thanks

Ahsan 09.15.09 at 17:43

very nice good thing, i was looking for it

Ravi 11.07.09 at 01:34

Thanks for tips… It is very useful. :)

Ravi Goswami 11.12.09 at 15:49

Hey !

Nice tips but this is not working for me. I have tried your same code . It shows me the flash in background but it overlaps the content.

Is there any otherway to show the content top of the flash?

Thanks

Ravi Goswami

Ronda Hutchings 11.20.09 at 14:09

I love this! Thanks for the instructions - very cool!

sudha 12.16.09 at 09:30

hey its working fine in IE & Firefox…
but not in safari….

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Previous post: Css3 opacity: transparency of an element in css

Next post: Css position: position static, absolute, relative and fixed of an element