Solved

Auto Center DIV's on Screen

Posted on 2007-11-15
4
6,289 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
This article discusses how to create an extensible mechanism for linked drop downs.
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…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

690 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