tags:

views:

373

answers:

2

Is it possible to have a div center aligned (ie) always i need to have the div in bottom center with fixed position in a specified width. I know to have it left or right? is there is any way?

+1  A: 
.myDiv
{
   position: fixed;
   bottom: 0px;
   width: 200px;
   margin-left: auto;
   margin-right: auto;
}
Ivan Zlatanov
Ivan, it's probably worth explaining that the width element is required in order for the `margin-left:auto; margin-right:auto;` bit to work. Also, I don't think you need `position:fixed`.
Dominic Rodger
Yes, the width is needed, else the div will have 100% width, and margins left and right make no difference :) position:fixed, because Webdevelopertut wanted the div to be positioned in the bottom center. I am not sure bottom: 0px; will work without any positioning.
Ivan Zlatanov
margin-left:auto and margin-right:auto wont work with position's like absolute and fixed.
Srikanth
A: 

I think this may help you

css:

 #parent{
    position:fixed;
    bottom:0px;
    width:100%;   //width should be 100%
 } 
 #child{
    width:100px; //min width should give to center the div.
    margin:0px auto; //here it will make center 
 }

HTML

<div id='parent'>
    <div id='child'>
      centered div
    </div>
</div>
Srikanth