2014-01-22 1 views
0
<style> 
body{margin:0; padding:0; position:fixed; } 
#container{width:1024; height:768px; background:#ccc; margin:0 auto;} 
</style> 

<body> 
<div id="container"></div> 
</body> 

사용자가 &을 클릭하면 나 자신이 팝 박스를 생성했습니다. 나는 몸을 설정하는 JQuery와 사용 position:fixed본문이 고정되어 있습니다. 컨테이너가 가운데를 맞출 수 없습니다.

내 문제는 몸 세트가 고정되면, 늘 중심을 (margin:0 auto)

이 랩퍼를 작성이 문제

+0

'body'에'position : fixed;'를 사용하면 안됩니다. 어떤 이유로 든 사용하고 싶다면'body' 내부에'div' 요소를 사용하십시오. –

+0

'position : fixed; ''body'에서 귀하의 콘텐츠를 스크롤 할 수 없게 만들 것입니다 ... 당신은 당신의 페이지에 그것을 원한다 !! : o – NoobEditor

답변

2

귀하의 경우., 신체에 width을 부여하면 작동합니다.

<style> 
body{width: 100%; margin:0; padding:0; position:fixed; } 
#container{width:1024px; height:768px; background:#ccc; margin:0 auto;} 
</style> 

<body> 
    <div id="container"></div> 
</body> 

p.s : 그건 그렇고, 당신은 왜 bodyposition:fixed을 적용 할 수 있습니까? 그냥 궁금해서 알아!

+0

안녕하세요 thx 많이, 그 이유는 내가 고정, 추가 1. 이유는 동일한 위치를 유지 2. 사용자 cant 스크롤 배경 (ipad 포함) – Ben

+0

괜찮아 :) Btw, 배경을 수정하려면 .. 당신이 사용했을 수도 'background-position : fixed'라고 생각합니다. – skshoyeb

+0

@BenWong : 그게 ... 배경 위치 : 고정 '을 사용할 수 있습니다 ...'신체 : 고정 '을 유지할 필요가 없습니다 – NoobEditor

1

를 해결할 수있는 방법입니다 정렬 포함입니다

HTML

<body> 
<div id="wrapper"> 
<div id="container"></div> 
</div> 
</body> 

CSS

,
#wrapper { 
position: relative; 
width: 100%; 
height: 100%; 
text-align: center; 
} 

#container { 
display: inline-block; // this is important, need this so it obeys the wrapper text-align: center rule 
width:1024; 
height:768px; 
background:#ccc; 
margin:0 auto; 
text-align: left; // add this if you have text you don't want centered 
} 
관련 문제