인라인 블록을 사용하여 상자를 표시 할 때 부모는 다음을 가질 수 있습니다. text-align:center;
두 번째 상자의 음수 여백 자신의 너비, 중간에 첫 번째 상자를 가져옵니다.
http://codepen.io/gcyrillus/pen/ADsEx
배경 - 색상 상자 서와 통치자가 시각적으로 수평 센터를 확인하기 위해 추가 위치를 표시하는 데 사용됩니다.
#top-menu {
display : inline-block;
width : 764px;
height : 55px;
background : green;
}
#social {
display : inline-block;
width : 100px;
height : 55px;
margin-right : -100px;
background : yellow;
}
#top-menu-wrapper {
text-align : center;
min-width : 990px;
background : purple;
}
div {
vertical-align : top;
padding : 5px 0;
}
.ruler {
width : 50%;
background : red;
margin : 5px 0 ;
}
이 방법을 사용하면 항상 2 줄을 한 줄에두기를 원하지 않는 한 부모의 너비를 신경 쓰지 않아도됩니다. 그렇다면 min-width : 충분히 넓게 적용 할 수 있습니다. 당신이 그것을 볼 수 있도록
또 다른 해결책 그것은 나를 위해 작동 2 상자에 포장 된 http://codepen.io/gcyrillus/pen/hipBl
body {
padding : 2em;
margin : 0;
}
#top-menu {
display : inline-block;
width : 764px;
height : 55px;
background : green;
}
#social, #top-menu-wrapper:before {
display : inline-block;
width : 100px;
height : 55px;
background : yellow;
}
#top-menu-wrapper:before {
content : '';
height : 0;
}
#top-menu-wrapper {
text-align : center;
min-width : 990px;
background : purple;
}
div {
vertical-align : top;
padding : 5px 0;
}
.ruler {
width : 50%;
background : red;
margin : 5px 0 ;
}
의 동일한 폭의 의사를 추가하는 것입니다, 난 그냥 div의에 색상을 추가했다. (http://jsfiddle.net/nbatothemax/G7uC9/) 아마도 문제는 컨테이너에 대한 헤더 컨테이너를 모두 지정하지 않았을 때,이 컨테이너 각각에 대한 부모로서'# header' ID를 가지고 있다는 것입니다. 그들. 또한 요소에 ID가있는 경우 부모 선택기를 사용하지 않아도됩니다. 부모 선택기를 사용하면 바로 가져올 수 있기 때문입니다. –