Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

CSS Forum


You are currently viewing our CSS Forum as a guest. Please register to participate.
Login



Reply
Help ragarding centering a <div>
Old 01-10-2011, 10:55 PM Help ragarding centering a <div>
Novice Talker

Posts: 5
Name: Aoun Muhammad
Trades: 0
Hi guys,
I am learning HTML and CSS now a days and I have started working on a site as making a site is best way to learn HTML and CSS.
I have a small problem.
I am not able to horizontally center my div.
I have tried almost all ways given as sticky.
When I use position: relative; it center my div in all browsers except IE but if use any other way to center my div, it simply does not show in any browser including IE.
Here is my code, any sort of help will be appreciated

CODE( That is centering in all other browsers except IE)
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Untitled Page</title>
<meta name="GENERATOR" content="Created by BlueVoda">
<style type="text/css">
div#headerbg
{ background-image:url(images/header_bg.png);
background-repeat:repeat-x;
   margin-top: 0px;
   margin-left: auto;
   margin-right: auto;
   text-align: left;
   height:88px;
}
div#header
{
   width: 870px;
   position: relative;
   margin-top: 0px;
   margin-left: auto;
   margin-right: auto;
   text-align: left;
}
body
{
   text-align: center;
   margin: 0;
}
</style>
</head>
<body bgcolor="#FFFFFF" text="#595959" link="#039BCA" vlink="#0393BC" alink="#00C3FF">
<div id="headerbg">
<div id="header">
<div id="headershade" style="overflow:hidden;position:absolute;left:1px;top:0px;z-index:0" align="left">
<img src="images/header_glow.png" id="Image2" alt="" align="top" border="0" style="width:862px;height:88px;"></div>
<div id="logo" style="overflow:hidden;position:absolute;left:0px;top:6px;z-index:1" align="left">
<img src="images/logo_05.png" id="Image3" alt="" align="top" border="0" style="width:369px;height:78px;"></div>
</div>
</div>
</body>
</html>
CODE(not showing any center in any browser)
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Untitled Page</title>
<meta name="GENERATOR" content="Created by BlueVoda">
<style type="text/css">
div#headerbg
{ background-image:url(images/header_bg.png);
background-repeat:repeat-x;
   margin-top: 0px;
   margin-left: auto;
   margin-right: auto;
   text-align: left;
   height:88px;
}
div#header
{
   width: 870px;
   margin: 0px auto;
   text-align: left;
}
body
{
   text-align: center;
   margin: 0;
}
</style>
</head>
<body bgcolor="#FFFFFF" text="#595959" link="#039BCA" vlink="#0393BC" alink="#00C3FF">
<div id="headerbg">
<div id="header">
<div id="headershade" style="overflow:hidden;position:absolute;left:1px;top:0px;z-index:0" align="left">
<img src="images/header_glow.png" id="Image2" alt="" align="top" border="0" style="width:862px;height:88px;"></div>
<div id="logo" style="overflow:hidden;position:absolute;left:0px;top:6px;z-index:1" align="left">
<img src="images/logo_05.png" id="Image3" alt="" align="top" border="0" style="width:369px;height:78px;"></div>
</div>
</div>
</body>
</html>
AounArts is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-10-2011, 11:20 PM Re: Help ragarding centering a <div>
Super Talker

Posts: 101
Trades: 0
I didn't debug your code but I see you have a lot of position attributes. There's no need for that, to center a div all you need to do is:

HTML Code:
<style type="text/css">

#divToCenter {
   width: 900px; /* necessary */
   height: 800px; /* optional */
   margin: 0 auto; /* necessary */
   border: 1px solid red; /* not necessary, just added so you can see the div */
}

</style>

<div id="divToCenter">
   some content
</div><!-- divToCenter -->
Towhid is offline
Reply With Quote
View Public Profile
 
Old 01-11-2011, 01:31 AM Re: Help ragarding centering a <div>
Novice Talker

Posts: 5
Name: Aoun Muhammad
Trades: 0
I tried that but it is not centering my div.
AounArts is offline
Reply With Quote
View Public Profile
 
Old 01-11-2011, 02:29 AM Re: Help ragarding centering a <div>
Novice Talker

Posts: 10
Name: JD
Trades: 0
hope this will help but avoid using to much positioning

Quote:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Untitled Page</title>
<meta name="GENERATOR" content="Created by BlueVoda">
<style type="text/css">
div#headerbg
{ background-image:url(images/header_bg.png);
background-repeat:repeat-x;
margin: 0 auto;
text-align: center;
height:88px;
}
div#header
{
width: 870px;
position: relative;
margin: 0 auto;
}
body
{
text-align: center;
margin: 0;
}
</style>
</head>
<body bgcolor="#FFFFFF" text="#595959" link="#039BCA" vlink="#0393BC" alink="#00C3FF">
<div id="headerbg">
<div id="header">
<div id="headershade" style=""><img src="images/header_glow.png" id="Image2" alt="" align="top" border="0" style="width:862px;height:88px;"></div>
<div id="logo" style="position: absolute; top: 0pt; left: 25%;"><img src="images/logo_05.png" id="Image3" alt="" align="top" border="0" style="width:369px;height:78px;"></div>
</div>
</div>
</body>
</html>
jsd132 is offline
Reply With Quote
View Public Profile
 
Old 01-11-2011, 08:13 AM Re: Help ragarding centering a <div>
LadynRed's Avatar
Defies a Status

Posts: 10,017
Location: Tennessee
Trades: 0
Read our stickies - http://tycoontalk.freelancer.com/css...r-website.html

The next question is what VERSION of IE are you having trouble with? Even nasty old IE6 understood margin: 0 auto; for centering.

What the others are trying to tell you is that all that relative and absolute positioning is generally not necessary and too much WILL cause problems with IE.
__________________
Web Goddess & Web Standards Evangelist :) - Tables Be Gone !!

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

LadynRed is offline
Reply With Quote
View Public Profile
 
Old 01-13-2011, 01:11 PM Re: Help ragarding centering a <div>
Novice Talker

Posts: 5
Name: Aoun Muhammad
Trades: 0
Quote:
Originally Posted by LadynRed View Post
Read our stickies - http://tycoontalk.freelancer.com/css...r-website.html

The next question is what VERSION of IE are you having trouble with? Even nasty old IE6 understood margin: 0 auto; for centering.

What the others are trying to tell you is that all that relative and absolute positioning is generally not necessary and too much WILL cause problems with IE.
When I remove the absolute positioning, it just displace my whole alignment.
AounArts is offline
Reply With Quote
View Public Profile
 
Old 01-13-2011, 03:58 PM Re: Help ragarding centering a <div>
LadynRed's Avatar
Defies a Status

Posts: 10,017
Location: Tennessee
Trades: 0
Then you need to learn to use floats and the normal document flow instead of positioning everything.
__________________
Web Goddess & Web Standards Evangelist :) - Tables Be Gone !!

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

LadynRed is offline
Reply With Quote
View Public Profile
 
Old 01-13-2011, 05:39 PM Re: Help ragarding centering a <div>
Novice Talker

Posts: 5
Name: Aoun Muhammad
Trades: 0
sure i'll learn what you told first.
AounArts is offline
Reply With Quote
View Public Profile
 
Old 02-07-2011, 02:53 AM Re: Help ragarding centering a <div>
Banned

Posts: 57
Name: Maria Cooper
Trades: 0
try this one:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Untitled Page</title>
<meta name="GENERATOR" content="Created by BlueVoda">
<style type="text/css">
#whole_page{
width:870px;

}
div#headerbg
{ background-image:url(images/header_bg.png);
background-repeat:repeat-x;
   margin-top: 0px;
   margin-left: auto;
   margin-right: auto;
   text-align: left;
   height:88px;
}
div#header
{
   width: 870px;
   position: relative;
   margin-top: 0px;
   margin-left: auto;
   margin-right: auto;
   text-align: left;
}
body
{
   text-align: center;
    margin-top: 0px;

  }
</style>
</head>
<body bgcolor="#FFFFFF" text="#595959" link="#039BCA" vlink="#0393BC" alink="#00C3FF">
<div align="center" >
<div id="whole_page">
<div id="headerbg">
<div id="header">
<div id="headershade" style="overflow:hidden;position:absolute;left:1px;top:0px;z-index:0" align="left">
<img src="images/header_glow.png" id="Image2" alt="" align="top" border="0" style="width:862px;height:88px;"></div>
<div id="logo" style="overflow:hidden;position:absolute;left:0px;top:6px;z-index:1" align="left">
<img src="images/logo_05.png" id="Image3" alt="" align="top" border="0" style="width:369px;height:78px;"></div>
</div>
</div>
</div>
</div>
</body>
</html>
maria_cooper is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Help ragarding centering a <div>
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.33738 seconds with 12 queries