Forum Moderators: not2easy

Message Too Old, No Replies

div in center

         

MarrkoR

10:10 pm on Aug 12, 2009 (gmt 0)

10+ Year Member



Hi,
I want to put the div in the middle of the page.

I found one:
pagetext-align: center; but work only with IE.

D_Blackwell

10:38 pm on Aug 12, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You are on the edge of asking two different questions here.

1) Centering the <div>

2) Centering the text within the <div>

These are two very different things. Below is a sample that does both.

NOTE: There are multiple options for centering the <div> It might be better in some situations to use the value 'auto' - {margin: 0 auto;}

Note: There is no 'pagetext-align' in the W3C recommendations. 'text-align:' is correct.
W3C - text-align [w3.org]

Validate your code for HTML and CSS. If it does not validate, errors should be fixed first. And code in FF or Opera, then fix for IE. Working in IE does not tell you much.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>
</title>
<meta http-equiv="content-style-type" content="text/css" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<style type="text/css" media="screen">
.center {
margin: 7em 15% 0 15%; text-align: center; font-size: 1.5em; border: .1em solid #000; padding: .5em;
}
</style>
</head>
<body>
<div class="center">
CENTERED
</div>
</body>
</html>

We_Are_Web

3:00 pm on Aug 14, 2009 (gmt 0)

10+ Year Member



I would generally use: margin: 0 auto;