Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you center <div> 's and Layers in different resolutions 1

Status
Not open for further replies.

WizyWyg

Technical User
Jan 31, 2001
854
JP
How do you center <div> 's and Layers in different resolutions?

I want the content of a page to be centered no matter what resolution that the visitor maybe in.

With tables this is very easy to do, but seeing that everyone saying that tables are bad for a layout, how can this be achieved using layers/divs ?
 
[tt]<div id=&quot;content&quot; style=&quot;text-align:center;&quot;><!-- Your content Here --></div>[/tt]

[sub]Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.
[/sub]
 
[tt]
<div style=&quot;text-align:center;&quot;>
[/tt]
Will centre-align the content of the <div>, not the <div> itself. There doesn't appear to be an explicit CSS property for getting a <div> to position along the centre, but I found a couple of indirect ways to do it. One is to use percentages:
[tt]
<div style=&quot;margin-left:10%;margin-right:10%&quot;>
[/tt]
Another is to use a second <div>:
[tt]
<div style=&quot;text-align:center&quot;>
<div style=&quot;width:400px;text-align:left&quot;>
<!-- Content in here -->
</div>
</div>
[/tt]
Or just use a table! ;-)

-- Chris Hunt
 
the only way would be to use javascript...

Known is handfull, Unknown is worldfull
 
Thanks, I actually found a site that has the code for it. And it works perfectly.
 
Theres a trick that uses absolute positioning with
negative margins... heres an example...

D.



<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;>

<html>
<head>
<title>Page title</title>

<Style>
.Centered200pxWide
{
position : absolute;
Width : 200px;
Left : 50%;
margin-left : -100px;
background-color : AliceBlue;
height : 100%;
top : 0px;
}
</Style>

</head>
<body>
<div class=&quot;Centered200pxWide&quot;> Some Text </Div>
</body>

</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top