如何做 - 將文字置於影像之上
瞭解如何將文字放置在影像上。
影像文字

左下角
左上角
右上角
右下角
居中
如何將文字放置在影像中
步驟 1) 新增 HTML
示例
<div class="container">
<img src="img_snow_wide.jpg" alt="雪景" style="width:100%;">
<div class="bottom-left">左下角</div>
<div class="top-left">左上角</div>
<div class="top-right">右上角</div>
<div class="bottom-right">右下角</div>
<div class="centered">居中</div>
</div>
步驟 2) 新增 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 定位的資訊,請閱讀我們的 CSS 定位 教程。