Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Center Div inside another (100% width) div

Tags:

css

xhtml

Quite a "simple" problem here and not sure why it's being so complicated.

  1. Have a 100% (width) sized div.
  2. Have another div positioned in the middle of this div (sized 940px width)

Any ideas? :)

like image 339
Shadi Almosri Avatar asked Sep 14 '09 20:09

Shadi Almosri


People also ask

How do I center a div with 100% width?

Just add margin: 0 auto; to the inside div.

How do I center a div inside another div?

To move the inner div container to the centre of the parent div we have to use the margin property of style attribute. We can adjust the space around any HTML element by this margin property just by providing desired values to it. Now here comes the role of this property in adjusting the inner div.

How do I center align two divs?

Just add margin: auto and a fixed width to the element you want to center, and the margins will force the element to center. There are a number of old methods to center multiple divs, but this is now much easier to do using modern CSS techniques.

How do I force a div to center?

Simply add text-align center to parent div and set the child div display to inline-block. This will force our div to behave like inline element and therefore subjected text-align center.


1 Answers

.parent { text-align: center; } .parent > .child { margin: 0 auto; width: 900px; } 
like image 167
geowa4 Avatar answered Sep 29 '22 15:09

geowa4