Forum Moderators: not2easy

Message Too Old, No Replies

Trouble with centering nested divs

         

madmartigan

5:01 pm on Apr 17, 2008 (gmt 0)

10+ Year Member



I wanted to disclaim in advance - especially being new to this particular forum - that I've been digging around for a couple days and still coming up empty on this. I'll apologize in advance if this has been addressed explicitly or implicitly already. That said, on to the issue at hand:

If you render this code you'll see a 100% height white stripe flanked by two 100% height thinner black stripes. No big deal, just three divs. However, I need to center those divs. I've tried the seemingly obvious "container div" but I'm missing something...probably and hopefully something trivial.

Here's the code, and thank you for any insight:


<!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">

html,body {
height: 100%;
}

body {
margin: 0px;
padding: 0px;
background-color:#717171;
text-align: center;
}

div#contentContainer {
height: 100%;
text-align: center;
margin: 0 auto;
}

div#stripeLeft {
width: 10px;
background-color:#000;
float: left;
height: 100%;
}

div#mainContent {
width: 980px;
height: 100%;
margin: 0px auto;
background-color: #fff;
float: left;
}

div#stripeRight {
width: 10px;
background-color:#000;
float: left;
height: 100%;
}

</style>

</head>

<body>

<!-- Container DIV -->
<div id="contentContainer">

<!-- Left stripe DIV -->
<div id="stripeLeft"></div>

<!-- Main content DIV -->
<div id="mainContent"></div>

<!-- Right stripe DIV -->
<div id="stripeRight"></div>

</div>

</body>
</html>

sgietz

5:18 pm on Apr 17, 2008 (gmt 0)

10+ Year Member



Hello,

You should specify a width for your content container.

birdbrain

5:26 pm on Apr 17, 2008 (gmt 0)



Hi there madmartigan,

and a warm welcome to these forums. ;)

As the widths of the #stripeLeft, #stripeRight and #mainContent divs total 1000px,
then this value must be set to the #contentContainer rule...


div#contentContainer {
width:1000px;
height: 100%;
text-align: center;
margin: 0 auto;
}


birdbrain

madmartigan

5:41 pm on Apr 17, 2008 (gmt 0)

10+ Year Member



Fantastic. I knew it was something ridiculously simple. Thanks very much for the extra sets of eyes. Works fine.

birdbrain

6:02 pm on Apr 17, 2008 (gmt 0)



No problem, you're welcome. ;)