[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Auto Center DIV's on Screen

Posted on 2007-11-15
4
Medium Priority
?
6,293 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 2000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
The first step to building an amazing About page is to figure out what you want the page to say about your company. You then must grab the attention of the reader, boast a bit, tell a story and let others brag about you. With a little bit of thought…
In this tutorial viewers will learn how add a full-size background image to a webpage using CSS3. Create a new HTML document with an internal stylesheet.: In CSS, define the html element to have a background image. Use a high resolution image.: In t…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

829 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