CSS 가운데 정렬에 대한 가이드

· 1년 전 · 511

홈페이지 제작에 있어서 컨텐츠를 가운데 정렬하는 것에 대한 요구는 많습니다.

고전적인 방법부터 최근 CSS 속성 이용까지... 이 부분은 참 많이 좋아졌습니다.

 

<div>내용</div>

 

1. margin을 이용한 멋진 중앙 정렬

 

<div class="c-center">내용</div>

 

.c-center{

 max-width: fit-content;

 margin-inline: auto;

}

 

2. flexbox를 이용한 정렬

 

<div class="c-center">내용</div>

 

.c-center{

 display: flex;

 justify-content: center;

 align-items: center;

}

 

3. viewport를 이용한 정렬

 

<div class="c-center">내용</div>

 

.c-center{

  position: fixed;

  inset: 0px;

  width: 12rem;

  height: 5rem;

  max-width: 100vw;

  max-height: 100dvh;

  margin: auto;

}

 

4. viewport를 이용한 정렬(크기를 모를 경우)

 

<div class="c-center">내용</div>

 

.c-center{

  position: fixed;

  inset: 0px;

  width: fit-content;

  height: fit-content;

  margin: auto;

}

 

5. grid를 이용한 정렬

 

<div class="c-center">내용</div>

 

.c-center{

  display: grid;

  place-content: center;

}

 

....

 

위에 언급한 것 외에 더 다양한 응용 방법들이 있겠지요? ^-^

 

 

웹학교 무료강좌 / 웹학교 컨텐츠몰 / PHP포탈

By 웹학교

 

|
댓글을 작성하시려면 로그인이 필요합니다.

365ok IT뉴스

+
제목 글쓴이 날짜 조회
1년 전 조회 449
1년 전 조회 337
1년 전 조회 550
1년 전 조회 542
1년 전 조회 388
1년 전 조회 401
1년 전 조회 356
1년 전 조회 396
1년 전 조회 471
1년 전 조회 464
1년 전 조회 581
1년 전 조회 470
1년 전 조회 500
1년 전 조회 404
1년 전 조회 512
1년 전 조회 462
1년 전 조회 522
1년 전 조회 775
1년 전 조회 415
1년 전 조회 495
1년 전 조회 451
1년 전 조회 1,949
1년 전 조회 482
1년 전 조회 437
1년 전 조회 456
1년 전 조회 544
1년 전 조회 677
1년 전 조회 515
1년 전 조회 428
1년 전 조회 695