0
点赞
收藏
分享

微信扫一扫

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

程序小小黑 2023-05-12 阅读 58


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

This specifies how far to offset the margin edges from the sides of the 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: You must define the width or this Answer will not work. That means this answer is not useful for elements with dynamic widths.



 

 

 

 

 

 

举报

相关推荐

0 条评论