• 회원가입
  • 로그인
  • 구글아이디로 로그인

[css] CSS - 블럭요소 수직중앙정렬/수평중앙정렬 (= 가로가운데정렬) (IE9) ★★★★★ (HT - Center Vertically) ※ 텍스트 수평정렬/수직정렬

목차 (= 2가지 방법)
  1. position 속성 이용
  2. flex 속성 이용

 

position 속성 이용 

※ IE9 이상 (ms 접두어 사용 O), IE10 이상
 

<style>

.hz { 

    height:100px;

    position: relative;

    border: 3px solid red; 

}


.hz p {

    margin: 0;

    position: absolute;

    top: 50%;

    left: 50%;

    -ms-transform: translate(-50%, -50%);

    transform: translate(-50%, -50%);

}

</style>


<div class="hz">

  <p>홈짱닷컴 Homzzang.com</p>

</div>


결과 보기

 

flex 속성 이용

[예제1] - 수평가운데정렬 / 수직가운데정렬

 

<style>

.hz {

    display: flex;    

    justify-content: center;    

    align-items: center;

    height: 100vh;

}
</style>

 

<div class="hz">

  <p>홈짱닷컴 Homzzang.com</p>

</div>

 

결과보기


[예제2] - 수평우측정렬 / 수직가운데정렬

 

<style>

.box li p {

    background-color: pink;

    display: flex;

    justify-content: flex-end; /* 수평정렬*/

    align-items: center; /* 수직정렬*/

    padding:5px;

}

.box li p b{font-size: 2rem;}

.box li p span{font-size: 1rem; margin-left:10px; display:inline-block; width:40px;}    

</style>


<ul class="box">

     <li>

        <h3>구조</h3>

        <p><b>HTML</b> <span>매우못함</span></p>

     </li>

     <li>

        <h3>디자인</h3>

        <p><b>CSS</b> <span>못함</span></p>

    </li>

</ul>

 

결과보기 

※ IE10 (접두어사용), IE11이상 지원.

관련글: 배르만 님 (230203) https://sir.kr/qa/488922


분류 제목
transition CSS - transition-duration 속성 ★ - 트랜지션 완료에 걸리는 시간 (= transiti…
transition CSS - transition-property 속성 - 트랜지션 효과 적용할 속성명 지정 (= transit…
transition CSS - transition-timing-function 속성 - 트랜지션 속도변경곡선 (= transit…
animation CSS - @keyframes 구문 - 애니메이션 코드 사용 선언 (= 애니사용 = @keyframes속성 …
animation CSS - animation 속성 ★ - 애니메이션 단축속성 (= animation속성 = 애니메이션속성, …
animation CSS - animation-delay 속성 - 애니지연시간 (= 작동지연시간 = 작동대기시간 = 작동준비시…
animation CSS - animation-direction 속성 - 애니방향 (= 움직임방향 = 애니메이션디렉션속성, I…
animation CSS - animation-duration 속성 - 애니지속시간 (= 애니완료소요시간 = 움직임완료소요시간…
animation CSS - animation-fill-mode 속성 - 애니미작동스타일 (= 움직임 작동안할때 스타일 = 애…
animation CSS - animation-iteration-count 속성 - 애니반복횟수 (= 움직임반복횟수, IE10…
animation CSS - animation-name 속성 - 키프레임명 (= 키프레임이름 = 애니이름 = 애니명 = 애니메…
animation CSS - animation-play-state 속성 - 애니재생상태 (= 애니작동상태설정 = 움직임 재생/…
animation CSS - animation-timing-function 속성 - 애니재생중속도변화 (= 움직임 중 속도변경…
image CSS - Rounded Images (둥근/동그란 이미지 만들기 = 이미지 테두리 둥글게/동그랗게) - I…
image CSS - Thumbnail Images - (썸네일 이미지 스타일)
image CSS - enter an Image (이미지 가운데정렬/중앙정렬)
image CSS - Image Text - (이미지 위에 텍스트 배치/띄우기)
image CSS - Polaroid Images / Cards - (폴라로이드 이미지)
image CSS - Image Filter - (이미지 필터 - 흑백/흐림 효과)
image CSS - Image Hover Overlay - (이미지 마우스오버시 효과 = 이미지허버효과 = 이미지마우…
9/25
목록
찾아주셔서 감사합니다. Since 2012