2014-03-14 2 views
0

내 사업부를 중심하려는 시도는 내 CSS의 :컨테이너 사업부 여기

#main { 
    background: #eae8dc; 
    margin: 0 auto; 
    width: 790px; 
    height: 900px; 
    position: relative; 
    display: block; 
} 
#header-container { 
    display: inline-block; 
    height: 118px; 
    width: 648px; 
    background: #9ed5de; 
    margin: 11px auto; 
} 

여기

<div id="main"> 
    <header> 
    <h1 id="header-container"> 
    </h1> 
    </header> 
</div> 

이 질문은 내 마진 문제를 해결하는 데 도움이 있었다 HTML이하지만 지금은없는 것 헤더 컨테이너를 가운데에 맞 춥니 다. Why does this CSS margin-top style not work?

답변

2

텍스트 정렬 당신이 그것을 중심 도움이 될 것입니다

#main { 
    background: #eae8dc; 
    margin: 0 auto; 
    width: 790px; 
    height: 900px; 
    position: relative; 
    display: block; 
    text-align: center; 
} 
#header-container { 
    display: inline-block; 
    height: 118px; 
    width: 648px; 
    background: #9ed5de; 
    margin: 11px auto; 
} 

다음은 JS 바이올린 http://jsfiddle.net/RBkmv/

+0

CSS는 너무 직관적이지 않습니다. (감사합니다. 분명히 작동하지만 #main의 모든 요소가 가운데에 위치합니까? 가능한 경우 피하고 싶습니다. – natecraft1

+0

예 - 가능하지 않은 경우 귀하의 접근 방식을 다시 생각해보아야하거나, 불만을 나타내는 50 % 왼쪽 여백에 의지해야합니다. – Trent

+0

이것을 달성하기 위해 html과 css를 구성하는 표준 또는 일반적인 방법은 무엇입니까? – natecraft1

1

이 나쁜 연습을합니다. 요소가 아닌 header 요소의 스타일을 지정해야하며 요소는 h1이 아닙니다. See example

#main { 
    background: #eae8dc; 
    margin: 0 auto; 
    width: 790px; 
    height: 900px; 
    position: relative; 
    display: block; 
    text-align: center; 
} 
header { 
    display: inline-block; 
    height: 118px; 
    width: 648px; 
    background: #9ed5de; 
    margin: 11px auto; 
} 

이 방법은 당신의 CSS 코드가 작동합니다.

+0

JSFiddle은 여전히 ​​그것을 가지고 있습니다. he H1 – Trent

+0

아니요, 스타일은 머리글 요소입니다. –