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

· 1년 전 · 454

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

고전적인 방법부터 최근 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년 전 조회 397
1년 전 조회 287
1년 전 조회 473
1년 전 조회 474
1년 전 조회 324
1년 전 조회 353
1년 전 조회 314
1년 전 조회 344
1년 전 조회 419
1년 전 조회 413
1년 전 조회 528
1년 전 조회 422
1년 전 조회 453
1년 전 조회 355
1년 전 조회 455
1년 전 조회 417
1년 전 조회 477
1년 전 조회 721
1년 전 조회 361
1년 전 조회 435
1년 전 조회 397
1년 전 조회 1,886
1년 전 조회 432
1년 전 조회 394
1년 전 조회 402
1년 전 조회 492
1년 전 조회 626
1년 전 조회 464
1년 전 조회 376
1년 전 조회 638
🐛 버그신고