Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't center a div container 1

Status
Not open for further replies.

tshad

Programmer
Jul 15, 2004
386
US
I have an issue where I am trying to line up 3 containers where the 1st container is on the left and the last container is on the right. The middle container would be in the center of the page. This allows the page to change sized with all containers being the same distance between each container.

I did get the outside containers to work correctly but not the middle container which contains some text and a couple of tables with customer data in it.

Here is a completely stripped down version of the problem.

It Is now an html file and this issue is, I want to center both the 1st text and the green box containing the second text. The div surrounding the green box won't center. It stays on the left.

What I really want is to center the div that surrounds the inner divs and have the 1st label left justified (inside the dive) so it is over the left side of the green box.

The purple box is the container of both texts. The green box and 1st text should move together as one unit but they don’t.

Code:
<!DOCTYPE html>
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
   <title></title>
</head>
<body>

   <div style="float: left; height: 50px; width: 60%; border: 1px solid red">
      <div style="text-align: center;">
         <div style="border: 1px solid purple">
            <div>
               <span>Enter Item Quantities and Then Add to List</span>
            </div>
            <div class="listboxBorderColor" style="border: 2px solid green;width: 445px;">
                 This is a test
            </div>
         </div>
      </div>
   </div>
</body>
</html>

Anyone know why this doesn't work?

Thanks,

Tom
 
You cannot 'float' a block element (other than float:none;) AND have it centered.

The text-align: property applies to inline child elements only.

To make a block element 'centre' in it's parent, requires it to have a set width (of less than the parent width) and have the left and right margins set to a value of 'auto;'.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
Hi Chris,

That was what I was looking for.

Thanks,

Tom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top