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.

HTML Forum


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



Post a Project »

Find a Professional HTML Freelancer!

Find a Freelancer to help you with your HTML projects

FREE Outsourcing eBook!

Reply
Old 05-19-2007, 06:03 PM Centering DIVs?
gsmile's Avatar
Skilled Talker

Posts: 99
Name: graceL
Trades: 0
So I've got a two-column layout and a header CSS div on my page. But then for some reason, the main content is below the sidebar. I've tried
HTML Code:
float : left
and everything else; it still doesn't work.
Any suggestions?
EDIT:
This is the code.
HTML Code:
} 
#top { 
width : 700px;
margin : 0 auto;
text-align : left;
} 
body { 
text-align : center;
} 
#side { 
width : 200px;
text-align : left;
float : left;
clear : both;
} 
body { 
text-align : center;
} 
#cmain { 
width : 560px;
margin : 0 auto;
margin-left : 340px;
text-align : left;
float : left;
clear : both;
} 
__________________

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

Last edited by gsmile; 05-19-2007 at 06:05 PM..
gsmile is offline
Reply With Quote
View Public Profile Visit gsmile's homepage!
 
 
Register now for full access!
Old 05-19-2007, 06:06 PM Re: Centering DIVs?
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,935
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
Trades: 0
clear : both; <-- that clears the left float. Take that out.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
(my blog)


Please login or register to view this content. Registration is FREE
(with proof)
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Old 05-19-2007, 06:12 PM Re: Centering DIVs?
gsmile's Avatar
Skilled Talker

Posts: 99
Name: graceL
Trades: 0
Both of the clear : both's?
__________________

Please login or register to view this content. Registration is FREE
gsmile is offline
Reply With Quote
View Public Profile Visit gsmile's homepage!
 
Old 05-19-2007, 06:36 PM Re: Centering DIVs?
gsmile's Avatar
Skilled Talker

Posts: 99
Name: graceL
Trades: 0
So basically, I need two divs under a parent div that are on the same line.
__________________

Please login or register to view this content. Registration is FREE
gsmile is offline
Reply With Quote
View Public Profile Visit gsmile's homepage!
 
Old 05-19-2007, 08:13 PM Re: Centering DIVs?
taketherisk's Avatar
Skilled Talker

Posts: 89
Name: Brett
Location: New Zealand
Trades: 0
Code:
#wrapper { 
text-align : center;
margin: 0px auto;
} 
#top {
width : 760px;
text-align : left;
} 
#side { 
width : 200px;
text-align : left;
float : left;
clear: left;
} 
#cmain { 
width : 560px;
text-align : left;
float : left;
}
See how that goes, don't forget to add the <div id="wrapper"></div> around everything.

Good luck
-Brett
__________________

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

Please login or register to view this content. Registration is FREE
taketherisk is offline
Reply With Quote
View Public Profile
 
Old 05-19-2007, 09:16 PM Re: Centering DIVs?
taketherisk's Avatar
Skilled Talker

Posts: 89
Name: Brett
Location: New Zealand
Trades: 0
Code:
<html>
<head>
<title>Untitled</title>
<style type="text/css">
<!--
#wrapper { 
text-align : center;
margin: 0px auto;
} 
#top {
width : 760px;
text-align : left;
border: 1px #000 solid;
} 
#side { 
width : 200px;
height: 600px;
text-align : left;
border: 1px #000 solid;
float: left;
} 
#cmain { 
width : 760px;
text-align : left;
height: 600px;
border: 1px #000 solid;
}
-->
</style>

</head>
<body>
<div id="wrapper">

<div id="top">
banner
</div>

<div id="cmain">
<div id="side">
side bar
</div>
Content
</div>

</div>
</body>
</html>
Here you go, i have tested this one...
__________________

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

Please login or register to view this content. Registration is FREE
taketherisk is offline
Reply With Quote
View Public Profile
 
Old 05-20-2007, 01:27 AM Re: Centering DIVs?
Skilled Talker

Posts: 77
Trades: 0
I have issues centering div's in IE from time to time. . . when all else fails I use
Code:
<div id="whatever" align=center>
and be sure I be sure to include this:

Code:
#whatever {
text-align: left;
}
I don't know what my issue is sometimes, but it's frustrating and as opposed to beating my head against my keyboard I use this approach.


. . . though maybe that wasn't your question (centering it)
__________________

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

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

Last edited by whooligan; 05-20-2007 at 01:28 AM.. Reason: I didn't read the first post correctly. . . sorry.
whooligan is offline
Reply With Quote
View Public Profile
 
Old 05-20-2007, 11:29 AM Re: Centering DIVs?
LadynRed's Avatar
Defies a Status

Posts: 10,017
Location: Tennessee
Trades: 0
You need to do 2 things to center a div and have it work cross-browser.

For non-IE browsers-
on your #wrapper (the container you want centered that holds everything else), make sure your #wrapper has a width defined and add

margin: 0 auto;
text-align: left; <-- puts the text back where it belongs

For IE add:
body{
text-align: center;
}

Adding "align: center" is not a good solution and should be avoided.
__________________
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


Last edited by LadynRed; 05-20-2007 at 11:31 AM..
LadynRed is offline
Reply With Quote
View Public Profile
 
Old 05-20-2007, 01:10 PM Re: Centering DIVs?
gsmile's Avatar
Skilled Talker

Posts: 99
Name: graceL
Trades: 0
Thanks a lot!! Talkputation added.
Quote:
Originally Posted by taketherisk View Post
Code:
<html>
<head>
<title>Untitled</title>
<style type="text/css">
<!--
#wrapper { 
text-align : center;
margin: 0px auto;
} 
#top {
width : 760px;
text-align : left;
border: 1px #000 solid;
} 
#side { 
width : 200px;
height: 600px;
text-align : left;
border: 1px #000 solid;
float: left;
} 
#cmain { 
width : 760px;
text-align : left;
height: 600px;
border: 1px #000 solid;
}
-->
</style>

</head>
<body>
<div id="wrapper">

<div id="top">
banner
</div>

<div id="cmain">
<div id="side">
side bar
</div>
Content
</div>

</div>
</body>
</html>
Here you go, i have tested this one...
__________________

Please login or register to view this content. Registration is FREE
gsmile is offline
Reply With Quote
View Public Profile Visit gsmile's homepage!
 
Old 05-20-2007, 08:20 PM Re: Centering DIVs?
gsmile's Avatar
Skilled Talker

Posts: 99
Name: graceL
Trades: 0
Now it works in FF but not in IE! And ideas?
__________________

Please login or register to view this content. Registration is FREE
gsmile is offline
Reply With Quote
View Public Profile Visit gsmile's homepage!
 
Old 05-20-2007, 08:58 PM Re: Centering DIVs?
Average Talker

Posts: 19
Trades: 0
Add:
Code:
margin: 0px auto;
to "#top" and "#cmain" and it should work in both!

I think. I hope. Maybe.
sappro is offline
Reply With Quote
View Public Profile
 
Old 05-20-2007, 11:56 PM Re: Centering DIVs?
taketherisk's Avatar
Skilled Talker

Posts: 89
Name: Brett
Location: New Zealand
Trades: 0
add

Code:
body{
text-align: center;
}
__________________

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

Please login or register to view this content. Registration is FREE
taketherisk is offline
Reply With Quote
View Public Profile
 
Old 05-21-2007, 01:15 AM Re: Centering DIVs?
gsmile's Avatar
Skilled Talker

Posts: 99
Name: graceL
Trades: 0
But then that makes the #cmain wrap around the #side, and when the #side ends, the #cmain takes up its space and gets bigger. But then I want the #side and #cmain to be seperate, the #wrapper wrapping it.
So how does it go?
__________________

Please login or register to view this content. Registration is FREE
gsmile is offline
Reply With Quote
View Public Profile Visit gsmile's homepage!
 
Old 05-21-2007, 01:41 PM Re: Centering DIVs?
LadynRed's Avatar
Defies a Status

Posts: 10,017
Location: Tennessee
Trades: 0
Ok, lets see the ACTUAL CODE. I gave you the answer you needed to center in IE and FF, you apparently chose to ignore that. The text-align: center should NOT make things shift the way you describe, but floats will if not cleared properly or if your widths are too wide.
__________________
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 05-21-2007, 10:50 PM Re: Centering DIVs?
gsmile's Avatar
Skilled Talker

Posts: 99
Name: graceL
Trades: 0
Quote:
Originally Posted by LadynRed View Post
Ok, lets see the ACTUAL CODE. I gave you the answer you needed to center in IE and FF, you apparently chose to ignore that. The text-align: center should NOT make things shift the way you describe, but floats will if not cleared properly or if your widths are too wide.
I DO have it. It's okay on the main page, but when you click on a post ( use wordpress), the #cmain is down under below the #side, not beside. Here's the code:
Code:
} 
body { 
text-align : center;
} 
#wrapper { 
text-align : center;
margin : 0 auto;
position : relative;
width : 800px;
} 
body { 
text-align : center;
} 
#top {
width : 800px;
margin : 0 auto;
text-align : left;
} 
body { 
text-align : center;
} 
#side { 
width : 200px;
text-align : left;
float: left;
} 
body { 
text-align : center;
} 
#cmain { 
width : 560px;
margin-left : 200px;
text-align : left;
}
__________________

Please login or register to view this content. Registration is FREE
gsmile is offline
Reply With Quote
View Public Profile Visit gsmile's homepage!
 
Old 05-22-2007, 02:15 PM Re: Centering DIVs?
LadynRed's Avatar
Defies a Status

Posts: 10,017
Location: Tennessee
Trades: 0
Lets see the HTML too. Is that ALL the CSS code ?
__________________
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 05-22-2007, 06:37 PM Re: Centering DIVs?
gsmile's Avatar
Skilled Talker

Posts: 99
Name: graceL
Trades: 0
Not all-- that's the div part.
Code:
<body>
<html>
<div id="wrapper">
<div id="top">
TOP STUFF


<div id="side">
<div class="content">
SIDE STUFF

</div>
</div>

<div id="cmain">
    <div id="content" class="narrowcolumn">
MAIN STUFF

</div>
</div>
</div>
</div>
</body></html>
__________________

Please login or register to view this content. Registration is FREE
gsmile is offline
Reply With Quote
View Public Profile Visit gsmile's homepage!
 
Old 05-23-2007, 06:30 PM Re: Centering DIVs?
gsmile's Avatar
Skilled Talker

Posts: 99
Name: graceL
Trades: 0
Any ideas?
__________________

Please login or register to view this content. Registration is FREE
gsmile is offline
Reply With Quote
View Public Profile Visit gsmile's homepage!
 
Old 05-24-2007, 12:10 AM Re: Centering DIVs?
taketherisk's Avatar
Skilled Talker

Posts: 89
Name: Brett
Location: New Zealand
Trades: 0
Ok this code works on FireFox 2, IE 7, IE 6, Opera 8.5

Code:
<html>
<head>
<title>Untitled</title>
<style type="text/css">
<!--
body {
  text-align: center;
}
#wrapper { 
text-align : center;
margin: 0px auto;
width: 760px;
} 
#top {
width : 760px;
text-align : left;
border: 1px #000 solid;
} 
#side { 
width : 200px;
height: 600px;
text-align : left;
border: 1px #000 solid;
float: left;
} 
#cmain { 
width : 760px;
text-align : left;
height: 600px;
border: 1px #000 solid;
}
-->
</style>

</head>
<body>
<div id="wrapper">

<div id="top">
banner
</div>

<div id="cmain">
<div id="side">
side bar
</div>
Content
</div>

</div>
</body>
</html>
Good luck with your site
__________________

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

Please login or register to view this content. Registration is FREE
taketherisk is offline
Reply With Quote
View Public Profile
 
Old 05-24-2007, 06:07 PM Re: Centering DIVs?
LadynRed's Avatar
Defies a Status

Posts: 10,017
Location: Tennessee
Trades: 0
#wrapper {
text-align : center;
margin: 0px auto;
width: 760px;
}

See that bolded line ?? Remove it, all that's going to do is make everything INSIDE #wrapper centered. If you remove THAT line, then you don't need all that extra 'text-align:left' on every other element.

The part that does the centering (for NON IE browsers) on #wrapper is margin: 0 auto combined with the defined width.

The text-align:center on body is what makes IE center.

I don't understand what's so difficult about that
__________________
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
 
Reply     « Reply to Centering DIVs?

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 1.46387 seconds with 12 queries