2015-01-01 2 views
0

나는 그들이 같은 수준에 있기를 원하지 않는다. 둘 다 독립 사업부입니다. 사이드 바가 고정됩니다. 사이드 바가 기사 div와 정렬되는 대신 상단에 붙지 않는 이유는 무엇입니까?기사 마진 - 상단 영향을받는 사이드 바 여백 - 상단

body{ 
    margin: 0; 
    padding: 0; 
} 

div#sidebar{ 
    background-color: yellow; 
    margin: 0; 
    padding: 0; 
    float: left; 
    height: 100%; 
    width: 200px; 
    position: fixed; 
} 

div#article{ 
    background-color: blue; 
    margin-left: 200px; 
    margin-top: 50px; 
    height: 500px; 
} 

HTML : top:-0px; :

<div id="sidebar"> 
    sidebar 
</div> 
<div id="article"> 
    article 
</div> 
+1

질문은 –

+1

가 어디 HTML 소스입니다 명확하지 않다? 귀하의 질문은 무엇인가? – QMaster

+0

내 질문은 왜 사이드 바가 기사 div와 정렬되는 대신 상단에 붙지 않는가? –

답변

1

이 트릭을 시도하십시오. 모르지만, 웬일인지 작동합니다!

body{ 
 
    margin: 0; 
 
    padding: 0; 
 
} 
 

 
div#sidebar{ 
 
    background-color: yellow; 
 
    margin: 0; 
 
    padding: 0; 
 
    float: left; 
 
    height: 100%; 
 
    width: 200px; 
 
    position: fixed; 
 
    top:-0px; /* <-- right here */ 
 
} 
 

 
div#article{ 
 
    background-color: blue; 
 
    margin-left: 200px; 
 
    margin-top: 50px; 
 
    height: 500px; 
 
}
<div id="sidebar"> 
 
    sidebar 
 
</div> 
 
<div id="article"> 
 
    article 
 
</div>