html - How to center absolute div horizontally using CSS? -


i've div , want centered horizontally - although i'm giving margin:0 auto; it's not centered...

.container {     position: absolute;     top: 15px;     z-index: 2;     width:40%;     max-width: 960px;     min-width: 600px;     height: 60px;     overflow: hidden;     background: #fff;      margin:0 auto; } 

you need set left:0; right:0;.

this specifies how far offset margin edges sides of window.

http://www.w3.org/tr/css2/visuren.html#position-props


http://jsfiddle.net/ss6dk/

css

.container {   position: absolute;   top: 15px;   z-index: 2;   width:40%;   max-width: 960px;   min-width: 600px;   height: 60px;   overflow: hidden;   background: #fff;   margin: 0 auto;   left: 0;   right: 0; } 

note: must define width or answer not work. means answer not useful elements dynamic widths.


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -