2017-09-20 10 views
1

나는 이것을 이해할 수 없다.왜 2 개의 인라인 블록 div가 조합 된 너비와 부모 맞춤의 크기가 나란히 정렬되어 있지 않습니까?

플로팅으로 작동 시키지만, 왜 이런 일이 일어나는지 이해하고 싶습니다.

pen

코드 : 당신이 하지 말자들이 인라인 요소의 공백에 민감하기 때문에 그건, 나란히 맞는 이유를 의미하는 경우

.container { 
 
    width: 1000px; 
 
    height: 400px; 
 
    background-color: purple; 
 
    position: relative; 
 
} 
 

 
.item { 
 
    height: 100px; 
 
    display: inline-block; 
 
} 
 

 
.item.left { 
 
    width: 70%; 
 
    background-color: green; 
 
} 
 

 
.item.right { 
 
    width: 30%; 
 
    background-color: orange; 
 
}
<div class="container"> 
 
    <div class="item left"></div> 
 
    <div class="item right"></div> 
 
</div>

답변

2

당신의 암호. div의 사이의 공간을 제거하고 그들은 같은 라인 나란히 늘어선 :

.container { 
 
    width: 1000px; 
 
    height: 400px; 
 
    background-color: purple; 
 
    position: relative; 
 
} 
 

 
.item { 
 
    height: 100px; 
 
    display: inline-block; 
 
} 
 

 
.item.left { 
 
    width: 70%; 
 
    background-color: green; 
 
} 
 

 
.item.right { 
 
    width: 30%; 
 
    background-color: orange; 
 
}
<div class="container"> 
 
    <div class="item left"></div><div class="item right"></div> 
 
</div>

+0

아, 감사합니다! 당신은 너무 빨리 대답했습니다. 아직 이것을 대답으로 표시조차 못합니다! 내 코드에 실제로 긴 줄을 넣지 않고 동일한 것을 수행 할 수 있습니까? – thesowismine

+0

'

'과 같은 줄 사이에 주석을 달거나 떠올리게 할 수도 있습니다. 덕분에 – j08691

+0

! 사실은 그 픽스를 잠시 후에 다시 떠 올렸습니다. 이것은 보통 전문가 수준에서 어떻게 처리됩니까? 공백 주석이 '해킹'으로 간주됩니까? 수레를 사용하는 것이 더 낫습니까? 이상한 논평을해야한다면 아마 이런 식으로해서는 안되는 것 같아? – thesowismine