html - 如何将文本/标题放在图像上?

标签 html css class

如何将标题放在每张图片的中央?例如在图像中心的第一个“音乐”

             <div class="row">
            <div class="item">
                <img src="images/music_cover.png"/>
             </div>
             <div class="item">
                <img src="images/event_cover.png"/>
             </div>
             <div class="item">
                <img src="images/lights_cover.png"/>
             </div>
         </div>

最佳答案

下面是CSS代码:

    /* Container holding the image and the text */
.container {
    position: relative;
    text-align: center;
    color: white;
}

/* Bottom left text */
.bottom-left {
    position: absolute;
    bottom: 8px;
    left: 16px;
}

/* Top left text */
.top-left {
    position: absolute;
    top: 8px;
    left: 16px;
}

/* Top right text */
.top-right {
    position: absolute;
    top: 8px;
    right: 16px;
}

/* Bottom right text */
.bottom-right {
    position: absolute;
    bottom: 8px;
    right: 16px;
}

/* Centered text */
.centered {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

下面是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>

我希望这对你有用。

关于html - 如何将文本/标题放在图像上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50807871/

相关文章:

html - CSS:只修改类中的一个元素

php - 如何将我的文本状态更改为按钮

css - 在文本后放置背景图像

ios - 子类 UIView 有两个标签

c++ - 带有模板的字符串堆栈?

javascript - 在复选框勾选上显示 div

html - 无法为 .png 图像使用动画

css float,清除问题

css - R Shiny : Interactively modify application theme

PHP 类以某种方式发生冲突