User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 360,995 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,462 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting

How to have the div layer center on any browser?

Join Date: Dec 2004
Posts: 1,589
Reputation: tgreer is an unknown quantity at this point 
Rep Power: 7
Solved Threads: 34
Colleague
tgreer tgreer is offline Offline
Made Her Cry

Re: How to have the div layer center on any browser?

  #21  
Nov 2nd, 2006
Originally Posted by bazmanblue View Post
in css you can assign divs to layers by numbers and is standard xhtml.


No, you cannot, as there is no such thing as "layers" in HTML, or XHTML. Plus, CSS cannot assign "divs" to anything at all. A DIV is an element, and CSS can apply styles to a DIV, but it cannot "apply" a DIV to anything. I think you need to go back to fundamentals. Drop Dreamweaver, learn the basic building blocks, and get your terminology down.

As I've explained, if you style your main container DIV properly, then DIVs defined inside of it will fall into place naturally. Start with a simple page:

[html]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Sample Page</title>
</head>

<body>
<div id="container">

</div>
</body>
</html>

[/html]
Now, create a CSS class, and assign it to the DIV.

[html]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Sample Page</title>
<style type="text/css">
.container
{
width: 200px;
margin: auto auto;
}
</style>
</head>

<body>
<div id="container" class="container">
<p>Some content to flesh out the div.</p>
</div>
</body>
</html>

[/html]
Add more CSS declarations to the class until it appears as you wish. Frankly, there is rarely a need to do any vertical centering. Users expect pages to start at the top of the browser, just as they expect words to appear at the top of book page. I would stick with simplistic, basic CSS.

Then, you simply add child DIVs.

[html]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Sample Page</title>
<style type="text/css">
.container
{
width: 200px;
margin: auto auto;
}
</style>
</head>

<body>
<div id="container">

<div id="child1"><p>A child div</p></div>
<div id="child2"><p>Another child</p></div>

</div>
</body>
</html>

[/html]

You can see if you copy my source code, that the child DIV elements automatically center, because of the relationship they have with the parent DIV.
Last edited by tgreer : Nov 2nd, 2006 at 5:36 pm.
Reply With Quote  
All times are GMT -4. The time now is 6:38 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC