如何使用 CSS 在图像上放置文本块?
cssweb developmentfront end technology更新于 2025/9/28 10:20:17
以下是使用 CSS 在图像上生成文本块的代码 −
示例
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.imageContainer {
display: inline-block;
position: relative;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif
}
.captionBlock {
position: absolute;
bottom: 20px;
right: 20px;
background-color: rgb(14, 0, 94);
color: rgb(255, 255, 255);
padding-left: 20px;
padding-right: 20px;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
</style>
</head>
<body>
<h1>Image Text Block Example</h1>
<div class="imageContainer">
<img src="https://i.picsum.photos/id/59/500/500.jpg" alt="Nature" style="width:100%;">
<div class="captionBlock">
<h3>Scenary</h3>
<h4>Fence on the ground</h4>
</div>
</div>
</body>
</html>
输出
上述代码将产生以下输出 −

相关文章
有用资源
css 参考教程 - 该教程包含有关 css 的更多信息:https://www.cainiaomax.com/css/

