您无法使用来做到这一点margin:auto
,但是您可以执行以下操作:
#css-SELECTOR-YOU-ARE-USING{
background:#FF0000; // Just so you can see whats going on
position:fixed; // Position the element
right:50%; // Move it to the right for 50% of parent element
margin-right:-250px; // You need here to put 1/2 of what you have below in width
width:500px;
}
这样,您可以将元素向右移动50%,然后向后移动其宽度的一半。这样,您将获得居中的元素position:fixed
。