이미지의 기본 표시 유형을 inline-block
으로 변경하고 inline-block
옆에 전체 높이 의사 요소를 생성 할 수 있습니다.
인라인 요소를 세로로 vertical-align: middle;
만큼 정렬하고 #box
에 text-align: center;
을 사용하여 이미지를 가운데로 가져옵니다.
또한 인라인 (-block) 요소 사이에 공백 문자가 있으므로 제거해야합니다. 당신은 my answer을 참조 할 수 있습니다. 여기
당신은 이동 :
#box {
/* Other styles here... */
text-align: center; /* align the inline(-block) elements horizontally */
font: 0/0 a; /* remove the gap between inline(-block) elements */
}
#box:after { /* create a full-height inline block pseudo=element */
content: ' ';
display: inline-block;
vertical-align: middle; /* vertical alignment of the inline element */
height: 100%;
}
#box img {
display: inline-block;
vertical-align: middle; /* vertical alignment of the inline element */
}
WORKING DEMO
더 자세한 내용은 my answer here를 참조 할 수 있습니다.
크기가 미지 인 이미지를 세로 및 가로 가운데에 정렬하려면 [내 대답은 여기에서]를 참조하십시오 (http://stackoverflow.com/questions/18516317/vertically-align-an-image-inside-a- div-with-responsive-height/18516474 # 18516474). –
이미지 크기가 변경됩니까? –
@HashemQolami 나는 피곤했지만 일할 수 없었다. – user3354493