3 Replies - 460 Views - Last Post: 14 July 2011 - 01:52 AM

#1 .james  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 02-July 11

JavaScript/ CSS popup

Posted 13 July 2011 - 11:14 AM

Hey,

I'm trying to make a Javascript-based popup (div) with an overlay designed to darken the rest of the screen. However, I'm having a problem with the overlay as it covers the pop-up div as well as the rest of the screen.

I've tried setting the z-index property of the popup to a higher value than that of the overlay but to no avail.

Some code to help illustrate my problem:

Javascript:


function showForm()
{
	var form = document.getElementById('contact_form');
	var screen = document.getElementById('form_screen');			
			
	screen.style.display = 'block';
	form.style.display = 'block';
			
}
function hideForm()
{
	var form = document.getElementById('contact_form');
	var screen = document.getElementById('form_screen');
	form.style.display = 'none';
	screen.style.display = 'none';
}



HTML:

<div id="form_screen">
</div>
<div id="contact_form">
	<h2>Get in touch</h2>			
</div>



Accompanying CSS:

#contact_form
{
	border: 3px solid #fff;
	-moz-border-radius: 5px;
	border-radius: 5px;
	background-color: #ccc;
	width: 350px;
	height: 300px;
	display: none;
	z-index: 3;
}
#form_screen
{
   background-color:#000;
   opacity: 0.3;
   position:absolute;
   top:0px;
   left:0px;
   width:100%;
   height: 100%;
   display: none;
   z-index: 2;
}



Can anyone see something I may be missing, or maybe someone has a solution other than z-index?

Thanks for any help!

Is This A Good Question/Topic? 0
  • +

Replies To: JavaScript/ CSS popup

#2 .james  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 02-July 11

Re: JavaScript/ CSS popup

Posted 13 July 2011 - 01:42 PM

Nevermind, literally left it to do another part of the website and it seems to have fixed itself. This always happens after I post a thread :hammer:
Was This Post Helpful? 0
  • +
  • -

#3 BiffBaffBoff  Icon User is offline

  • D.I.C Head

Reputation: 20
  • View blog
  • Posts: 77
  • Joined: 10-February 11

Re: JavaScript/ CSS popup

Posted 13 July 2011 - 03:51 PM

Just a note: In order for the z-index property to work, the element has to have the position property set also. Your #contact_form in the code above doesn't have a position property set to it so its z-index won't be functioning as you want it too. The fact that you said the problem fixed itself is probably because your #form_screen element does have the position and z-index properties set.
Was This Post Helpful? 1
  • +
  • -

#4 .james  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 02-July 11

Re: JavaScript/ CSS popup

Posted 14 July 2011 - 01:52 AM

View PostBiffBaffBoff, on 13 July 2011 - 03:51 PM, said:

Just a note: In order for the z-index property to work, the element has to have the position property set also. Your #contact_form in the code above doesn't have a position property set to it so its z-index won't be functioning as you want it too. The fact that you said the problem fixed itself is probably because your #form_screen element does have the position and z-index properties set.


That was indeed the problem. I've realised I must have set the position property while rearranging it on-screen which caused it to work. Thanks for replying.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1