CSS水平居中的固定div? [英] CSS horizontal centering of a fixed div?
本文介绍了CSS水平居中的固定div?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#menu {
position: fixed;
width: 800px;
background: rgb(255, 255, 255); /* The Fallback */
background: rgba(255, 255, 255, 0.8);
margin-top: 30px;
}
我知道这个问题是一百万次,但我不能找到一个解决我的情况。
我有一个div,应该固定在屏幕上,即使页面被滚动,它应该总是保持CENTERED在屏幕中间!
I know this question is a million times out there, however I can't find a solution to my case. I've got a div, which should be fixed on the screen, even if the page is scrolled it should always stay CENTERED in the middle of the screen!
div应该有 500px
width,应该距离顶部(margin-top) 30px
The div should have 500px
width, should be 30px
away from the top (margin-top), should be horizontally centered in the middle of the page for all browser sizes and should not move when scrolling the rest of the page.
这是否可能?
推荐答案
请参阅@MaciejKrawczyk更新解答,不需要固定宽度。
left: 50%;
margin-left: -400px; /* Half of the width */
这篇关于CSS水平居中的固定div?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文