만들기 방법: 이미지 위에 텍스트 위치를 설정

이미지 위에 텍스트를 배치하는 방법을 배우세요.

이미지 텍스트

베이징
Bottom Left
Top Left
Top Right
Bottom Right
Centered

직접 시도해보세요

이미지 안에 텍스트를 배치하는 방법

第一步 - HTML 추가:

<div class="container">
  <img src="img_snow_wide.jpg" alt="Snow" style="width:100%;">
  <div class="bottom-left">Bottom Left</div>
  <div class="top-left">Top Left</div>
  <div class="top-right">Top Right</div>
  <div class="bottom-right">Bottom Right</div>
  <div class="centered">Centered</div>
</div>

第二步 - CSS 추가:

/* 이미지와 텍스트를 포함하는 컨테이너 */
.container {
  position: relative;
  text-align: center;
  color: white;
}
/* 왼쪽 하단 텍스트 */
.bottom-left {
  position: absolute;
  bottom: 8px;
  left: 16px;
}
/* 왼쪽 상단 텍스트 */
.top-left {
  position: absolute;
  top: 8px;
  left: 16px;
}
/* 오른쪽 상단 텍스트 */
.top-right {
  position: absolute;
  top: 8px;
  right: 16px;
}
/* 오른쪽 하단 텍스트 */
.bottom-right {
  position: absolute;
  bottom: 8px;
  right: 16px;
}
/* 중앙에 텍스트 */
.centered {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

직접 시도해보세요

관련 페이지

교육:}}CSS 이미지

교육:}}CSS 정위치