여기 jsfiddle이 있습니다 : http://jsfiddle.net/techsin/1o5zzcgh/
jquery를 사용하지 않고 두 개의 절대 위치 div를 서로 중앙에 배치하고 싶습니다. 지금은 top : 0 및 bottom 0을 사용하고 있지만 높이가 정의되면 작동하지 않습니다.
* {
margin: 0;
padding: 0;
}
html, body {
position: relative;
height: 100%;
width: 100%;
}
.in, .out {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
.in {
background-color: red;
height: 50%;
}
.out {
background-color: blue;
}
여백 을 추가해야합니다 : 자동; 절대 위치 div에 적용한 다음 height : 50 % 를 적용합니다 . 그리고 폭 : 50 %; .in div.
* {
margin: 0;
padding: 0;
}
html, body {
position: relative;
height: 100%;
width: 100%;
}
.in, .out {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin:auto;
}
.in {
background-color: red;
height: 50%;
width:50%;
}
.out {
background-color: blue;
}
JSFIDDLE : http://jsfiddle.net/a_incarnati/1o5zzcgh/1/
높이를 설정할 수도 있지만 컨테이너가 100 %이기 때문에 사각형이 아니라는 점을 기억해야합니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다