...

View Full Version : center div



BubikolRamios
11-20-2012, 06:47 AM
Can't get "problem" div to be centered on page.

Any tip ?



<html>
<head>
<style type="text/css">
.a0v1
{
width:320px;
background:#E3E9DD;
border:1px solid gray;
text-align:center;
}
</style>
</head>


<body>
<div style ="text-align:center;">
<div id ="problem" class="a0v1">
foo
</div>
</div>
</body>
</html>

Excavator
11-20-2012, 07:14 AM
Hello BubikolRamios,
To center an element you need three things:

a valid DocType
an element with a width
that elements right/left margins set to auto



Like this -
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
.a0v1 {
width: 320px;
margin: 0 auto;
background: #E3E9DD;
border: 1px solid gray;
text-align: center;
}
</style>
</head>
<body>
<div id ="problem" class="a0v1"> foo </div>
</body>
</html>

BubikolRamios
11-20-2012, 07:23 AM
jeah, I know all that, was pushing around "margin: 0 auto;", but it didn't want to hit right place (-:

Thanks.

Excavator
11-20-2012, 07:32 AM
Maybe a better description would get you a better answer.

BubikolRamios
11-20-2012, 07:53 AM
Don't get me wrong, your answer was excelent.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum