DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/)
-   JavaScript / DHTML / AJAX (http://www.daniweb.com/forums/forum117.html)
-   -   How to have the div layer center on any browser? (http://www.daniweb.com/forums/thread60286.html)

bazmanblue Nov 2nd, 2006 9:29 am
How to have the div layer center on any browser?
 
hello im trying to get my div layer to align so that it centers on the browser so it doesnt matter about the size of somones browser it will always be centered on the page. i have tried
[HTML]<div align="center" class="style1" id="Layer1">[/HTML]
but this doesnt seem to work when i view it in my browser and make the browser page smaller. i am doing this in dreamweavers test browser, could this be the problem? any help would be very much apreciated

BudBrocken Nov 2nd, 2006 10:11 am
Re: How to have the div layer center on any browser?
 
align=center doesn't work on divs.
try this:

body {
    text-align: center;
}
.style1 {
    margin: auto auto;
}

bazmanblue Nov 2nd, 2006 10:33 am
Re: How to have the div layer center on any browser?
 
thanks but i have tried that and this way but it still doesnt work for some reason
[HTML]#Layer1 {
position:absolute;
width:800px;
height:800px;
margin-right:auto;
margin-right:auto;
}[/HTML]
is it the position absolute that i need to delete? might try that now

bazmanblue Nov 2nd, 2006 10:35 am
Re: How to have the div layer center on any browser?
 
nope not the position absolute either:rolleyes:

BudBrocken Nov 2nd, 2006 10:35 am
Re: How to have the div layer center on any browser?
 
indeed, it won't work with absolute positioning

BudBrocken Nov 2nd, 2006 10:36 am
Re: How to have the div layer center on any browser?
 
use
margin: auto auto;
don't use
margin-right: auto;
margin-right: auto;
and don't forget
body {
    text-align: center;
}

bazmanblue Nov 2nd, 2006 10:41 am
Re: How to have the div layer center on any browser?
 
aha thanks your a star! do you know how i keep the divs inside this div from moving?
i.e there left and top attributes?

bazmanblue Nov 2nd, 2006 10:55 am
Re: How to have the div layer center on any browser?
 
ive got the main layer to staycentral thanks. but how do i keep the layers on top of this in the same position on that layer when the browser size changes?

bazmanblue Nov 2nd, 2006 10:59 am
Re: How to have the div layer center on any browser?
 
this is how i have set the layers over another layer
[HTML]<div class="style1" id="Layer1"><img src="dmlayer1.png" width="800" height="800" />
<div id="Layer7"></div>
<div id="Layer6"></div>
<div id="Layer5">
<div align="left"> </div>
</div>
<div id="Layer4">
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="501" height="115">
<param name="movie" value="dmtitle.swf" />
<param name="quality" value="high" /><param name="LOOP" value="false" />
<embed src="dmtitle.swf" width="501" height="115" loop="false" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed>
</object>
</div>
<div id="Layer2">
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="150" height="150">
<param name="movie" value="fruitdm.swf" />
<param name="quality" value="high" />
<embed src="fruitdm.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="150" height="150"></embed>
</object>
</div>
</div>[/HTML]

and this is how one of the layers is currently set out in css

[HTML]#Layer3 {
position:absolute;
width:200px;
height:115px;
z-index:2;
left: 314px;
top: 32px;
background-color: #FFFFFF;
}[/HTML]

tgreer Nov 2nd, 2006 12:54 pm
Re: How to have the div layer center on any browser?
 
In all of this discussion, "doctype" hasn't been mentioned. It is impossible to tell you what HTML/CSS code to use if we don't know which version of HTML/CSS you're using.


All times are GMT -4. The time now is 4:00 am.

Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC