Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我进行了广泛搜索,但似乎找不到我的特定问题的答案:我有一个 980 像素宽的 div,并且位置:固定在向下滚动时保持在页面顶部。我的问题是我无法弄清楚如何使 div 居中对齐,并保持居中,同时也是位置:固定而不是位置:相对
任何迹象,还是我错过了一些明显的东西?
您可以应用此 CSS 样式:
div#id { position:fixed; top:0; /* or whatever you need */ left:50%; width:980px; margin-left:-490px; /* half the lenght of the element */ }
按照 GionaF 的正确答案,这里有一个活生生的例子。
http://jsfiddle.net/Ubp49/