Solved

Auto Center DIV's on Screen

Posted on 2007-11-15
4
6,283 Views
Last Modified: 2008-02-01
Hey there,

I have a bunch of DIV's that I'm using as pop ups to show additional content using the visibility property.  

Is there a way (say through CSS) that I can get these pop ups to always appear in the center of the clients screen?

TIA
0
Comment
Question by:ttist25
  • 2
4 Comments
 
LVL 14

Accepted Solution

by:
cezarF earned 500 total points
ID: 20294659
use this style..

#screenCenter {
    width:300px;
    height:200px;
    position:absolute;
    top:50%;
    left:50%;
    margin:-100px auto auto -150px;
    border:1px solid #000;
    background-color:#F2F5F6;
}

note that the "-100px" and  "-150px" in the "margin:-100px auto auto -150px;" are the halves (50%) of height and width styles accordingly
0
 
LVL 2

Expert Comment

by:ToastedWeb
ID: 20297387
@cezarF : this also means that you must specify the width and height of container (div)
0
 
LVL 14

Expert Comment

by:cezarF
ID: 20297858
@ToastedWeb:that's right
0
 
LVL 1

Author Comment

by:ttist25
ID: 20299088
First, thanks for the response.  It is greatly appreciated.  

I can't seem to get this to work correctly.  I probably should have elaborated a bit more as to my design.  I'm using layout tables for the page layout.  In my layout cells, I have text and a small image.  

I'm using onmouseover and javascript to set the visibility of my layers.  The layers are using nested DIV's and a .js file to create a slideshow as seen here:  http://www.dynamicdrive.com/dynamicindex17/featuredcontentslider.htm

Plus, I don't know what the hell I'm doing.  heh!

Considering all this additional information I should have posed in my initial question but didn't, is it possible to center on screen using the method you described?  

If not, is there a way to anchor the position of the layer to an object (like an image)?

Thanks again and sorry for leaving all of that out.

PS - here's a smippet of one of my DIV's
<div id="slider1" class="LayerStyle1" style="position : absolute; left: 165px; top: 259px; z-index: 19; visibility: hidden;">

		 <div class="opacitylayer">

				<img alt="close" src="close_button.jpg" width="16" height="16" style="float: none" onclick="FP_changeProp(/*id*/'slider1',0,'style.visibility','hidden'); FP_changeProp(/*id*/'paginate-slider1',0,'style.visibility','hidden')">

				<div class="contentdiv">

				<img class="smallHorseImage" alt="Content1ALt" src="horses/horse1.jpg" width="400" height="300"><br>

				Image 1				

				</div>

				

				<div class="contentdiv">

				<img class="smallHorseImage" alt="" src="horses/horse2.jpg" width="400" height="300"><br>

				Image 2			

                                </div>

				

				<div class="contentdiv">

				<img class="smallHorseImage" alt="" src="horses/horse3.jpg" width="400" height="300"><br>

				Image 3

				</div>

				

				<div class="contentdiv">

				<img class="smallHorseImage" alt="" src="horses/horse4.jpg" width="400" height="300"><br>

				Image 4

             			</div>		

				<div class="contentdiv">

				<img class="smallHorseImage" alt="" src="horses/horse5.jpg" width="400" height="300"><br>

				Image 5

				</div>

				

		 </div>

		 <div style="visibility: hidden; z-index: 20"  id="paginate-slider1" class="pagination">

		 </div>

		</div>

Open in new window

0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now