4 replies [Last post]
alex3oo2
alex3oo2's picture
User offline. Last seen 1 year 40 weeks ago. Offline
newbie
Timezone: GMT-4
Joined: 2010-03-14
Posts: 3
Points: 5

ok so here is the code:

<div style="position: absolute; background: blue;top: 25px; height:500; width: 1800px;overflow:hidden;margin-left: auto; margin-right: auto;">
<div style="position: absolute; width:800; height:400px; background: red;">
 
	<div style="position: absolute; background: green; width: 100px; height: 330px; left:25px">
	menu
	</div>
 
	<div style="position: absolute; background: green; width: 500px; height: 330px; left:145px">
	main
	</div>
 
	<div style="position: absolute; background: green; width: 100px; height: 330px; left:670px">
	options
	</div>
 
 
</div>
</div>

I made a small example of the site. If you run the code then you will notice that the site will be contained in a red box which is aligned to the left in the blue box which represents the background. I would like the red box to be centered and have tried to use margin-left: auto; margin-right: auto; as in the code above and text-align: center;. none of this is working so I assume that I am doing something wrong. If anyone can help me center the red block in the blue block, it would be highly appreciated.

Thank you,
-Alex

Hugo
Hugo's picture
User offline. Last seen 57 min 20 sec ago. Offline
rank Moderator
Moderator
Joined: 2004-06-06
Posts: 15096
Points: 2191

Why Oh Why with the

Why Oh Why with the position:absolute?

Lose all those positional properties simply set widths and your auto margins.

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me

alex3oo2
alex3oo2's picture
User offline. Last seen 1 year 40 weeks ago. Offline
newbie
Timezone: GMT-4
Joined: 2010-03-14
Posts: 3
Points: 5

Ok I removed the position

Ok I removed the position absolute part but the margin auto code is still not working correctly

<div style="background: blue;top: 25px; height:500; width: 1800px;overflow:hidden; margin-left: auto; margin-right: auto;">
	<div style="width:800; height:400px; background: red;">
 
		<div style="position: absolute; background: green; width: 100px; height: 330px; left:25px">
		menu
		</div>
 
		<div style="position: absolute; background: green; width: 500px; height: 330px; left:145px">
		main
		</div>
 
		<div style="position: absolute; background: green; width: 100px; height: 330px; left:670px">
		options
		</div>
 
 
	</div>
</div>

Deuce
Deuce's picture
User offline. Last seen 3 days 2 hours ago. Offline
rank Guru
Guru
Timezone: GMT-6
Joined: 2005-11-20
Posts: 4416
Points: 1835

alex3oo2 wrote: Ok I removed

alex3oo2 wrote:

Ok I removed the position absolute part

No you didn't, I still count three pos:abs

all ยป http://dictionary.reference.com/browse/all

Google isn't a bunch of guys reading and grading web sites, it's more like a bunch of monkeys sniffing food and putting the good bananas at the top. -Triumph

Hugo
Hugo's picture
User offline. Last seen 57 min 20 sec ago. Offline
rank Moderator
Moderator
Joined: 2004-06-06
Posts: 15096
Points: 2191

shrugging and wondering why

shrugging and wondering why it was necessary to reiterate, Hugo originally wrote:

Lose all

Then lets see how things stack up, and while at it ensure you declare units with all values, and move those inline styles to embedded styles while testing.

Edit/ ought to add that the three inner elements will need to be floated to force them to sit side by side.

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me