반응형
이미지 높이 중앙 정렬
align="absmiddle"를 CSS로 변경 방법 style="vertical-align:middle"
핵심 내용
img { vertical-align: middle }
Ever got stuck with the annoying problem of aligning an image next to some text? We all did. There were times when align="absmiddle" would solve this immediately, but how would you accomplish this with CSS?
Ever got stuck with the annoying problem of aligning an image next to some text? We all did. There were times when align="absmiddle" would solve this immediately, but how would you accomplish this with CSS? The truth of the matter is that absmiddle is a proprietary attribute that is not supported in any HTML version. The simple solution for this problem is using the 'vertical-align' css property:
Test 1:
<style type="text/css">
div img { vertical-align: middle }
</style>
Furthermore, if you notice careful at the results of vertical-align (or even the proprietary absmiddle), often the alignment is not perfectly in the middle, but slightly closer to the top. You can add a small bottom margin to make it perfectly centered to the middle:
Test 2:
<style type="text/css">
div img { vertical-align: middle; margin-bottom: .25em }
</style>
Notice that in all tests, behaviour will depend on the containing block style, for example, if the containing div is float to left, or display block.
Here are the results for the three tests I wrote, notice how the vertical-align and absmiddle are identical, while not perfectly in the middle. The second test, uses the margin-bottom: .25em to nudge the text straight to the middle.
Test 1:
<style type="text/css">
div img { vertical-align: middle }
</style>
Furthermore, if you notice careful at the results of vertical-align (or even the proprietary absmiddle), often the alignment is not perfectly in the middle, but slightly closer to the top. You can add a small bottom margin to make it perfectly centered to the middle:
Test 2:
<style type="text/css">
div img { vertical-align: middle; margin-bottom: .25em }
</style>
Notice that in all tests, behaviour will depend on the containing block style, for example, if the containing div is float to left, or display block.
Here are the results for the three tests I wrote, notice how the vertical-align and absmiddle are identical, while not perfectly in the middle. The second test, uses the margin-bottom: .25em to nudge the text straight to the middle.
출처: http://www.web-sheeps.com/rec/69-Image-vertical-align-with-CSS,-avoid-abs
반응형
'Web > WEB기본' 카테고리의 다른 글
[CSS] CSS 글 자간 줄간 설정 (0) | 2013.12.17 |
---|---|
[CSS] 배경 이미지 고정하기 ( background-attachment 속성 ) (2) | 2013.11.14 |
[CSS] CSS Values and Units Module Level 3 수치 단위 (0) | 2013.10.24 |
[CSS] CSS 속성 inherit 상속받기 (0) | 2013.10.23 |
[CSS] CSS 애니메이션 처리 (0) | 2013.10.12 |
[CSS] webkit에서 사용되는 CSS text-align 속성값들 (0) | 2013.10.12 |
[html5] canvas 태그 clear (for redrawing) (0) | 2013.09.26 |
[favicon]즐겨 찾기 사이트의 대표 icon 만들기 (0) | 2013.06.26 |
도움이 되셨다면 하트모양의 "♡ 공감"을 눌러주시면 큰 격려가 됩니다.
(로그인하지 않으셔도 가능)
(로그인하지 않으셔도 가능)