CSS:absolute居中 How to center absolute div horizontally using CSS

You need to set left:0; right:0;.

This specifies how far to offset the margin edges from the sides of the window.




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

Note: You must define the width or this Answer will not work. That means this answer is not useful for elements with dynamic widths.

share from: http://stackoverflow.com/a/17977312


本文:CSS:absolute居中 How to center absolute div horizontally using CSS


Add a Comment

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.