Solved

Auto Center DIV's on Screen

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
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 Micro Tutorial viewers will learn how to create a CSS image sprite (In a later tutorial, viewers will learn how to use CSS and HTML to create a navigation menu using this sprite) Open a new Photoshop document with a width of (Icon width)x(N…
In this tutorial viewers will learn how to style a decorative dropcap for the first letter in a paragraph using CSS. In CSS, create a new paragraph class by typing "p.fancy": Then, to style only the first letter of the first sentence, include the ps…

685 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