چگونه ایجاد می‌شود: متنی را روی تصویر قرار دهید

آموزش چگونه متنی را روی تصویر قرار دهیم.

متون تصویر

بئیجینگ
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 مکان‌دهی