Solved

Auto Center DIV's on Screen

Posted on 2007-11-15
4
6,287 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
javascript delete path 7 43
CSV export single column not inserting comma's in file 11 65
Horizontal Full Calendar using php 5 42
Add Promise to Existing Code 6 27
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
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 …
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

737 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