|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
How can I center a div on a page?
I have a div sitting on a html page that will be included in the main page.
I include this page into a table and I would like the div to be centered horizontally inside the table cell. It isn't working for me at the moment. Am I doing something wrong? Here is what I have so far: Code:
#mybox{
border-style: solid;
border-width: 1px;
border-color: #000000;
padding: 5px;
width: 400px;
left-margin:auto;
right-margin:auto;
}
Brad. |
|
#2
|
||||
|
||||
|
Quote:
left-margin/right-margin should be reversed: PHP Code:
![]()
__________________
Proud member of the T.S.N.B.U.F.L (tables should not be used for layout) alliance. "Only use elements for their intended purpose. You wouldn't try to make coffee with a telephone, would you?" -Me |
|
#3
|
|||
|
|||
|
It still doesn't work.
I think I'll just use tables. From my searches here and on google it looks like divs will be a PITA for what I am trying to do. EDIT: Nope...this is a pain...I need to use a div because I want that nice thin border. Surely I should be able to center a div on a blank page. This is the code I have: Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<STYLE TYPE="text/css">
body {
text-align: center; /* for IE */
}
.bodytext {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 11px;
font-weight: normal;
color : #000000;
}
#heading11 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 11px;
font-weight: bold;
color : #000000;
}
#mybox{
margin: 0 auto; /* align for good browsers */
text-align: left; /* counter the body center */
border-style: solid;
border-width: 1px;
border-color: #000000;
padding: 5px;
width: 400px;
}
</STYLE>
</head>
<body>
<div id="mybox">The quick brown dog jumps over the lazy fox.</div>
</body>
</html>
|
|
#4
|
|||
|
|||
|
Well I can't see the problem.
It centres itself in the middle of my browser at the top. Do you mean you want it in the middle of the page or you want the text central in the box?
__________________
Tried and tested FREEBIES-4-YOU !! http://www.freebies-4-you.com |
|
#5
|
|||
|
|||
|
Gary's version always works for me...
Try this:
Code:
<!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 name="generator"
content="HTML Tidy for Linux/x86 (vers 1st March 2002), see www.w3.org" />
<meta http-equiv="content-type"
content="text/html; charset=ISO-8859-1" />
<title>Centering Horizontally</title>
<style type="text/css">
/*<![CDATA[*/
html, body, {
margin: 0;
padding: 0;
text-align: center; /*for IE stupidity*/
}
p {
font-size: 1em;
text-indent: 2em;
}
#container {
position: relative; /*The container must be positioned
/*in order to contain positioned
/*elements*/
margin: 0 auto; /*This is the proper way to center an element*/
width: 620px;
border: 1px solid blue;
text-align: left; /*corrects for IE hack*/
padding: 1px;
}
/*]]>*/
</style>
</head>
<body>
<div id="container">
<p>This division will be horizontally centered in the browser
viewport. It can be used to hold the “page.” The
container will stretch vertically according to the content.</p>
</div>
<!-- end container div -->
</body>
</html>
|
|
#6
|
||||
|
||||
|
Yeah, I forgot to mention that the div's parent element needs to have "text-align: center;"
PHP Code:
Oops. ![]() |
![]() |
| Viewing: Dev Shed Forums > Web Design > CSS Help > How can I center a div on a page? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|