如何使用 CSS 创建带有透明背景文字的图片?
cssweb developmentfront end technology更新于 2025/9/28 10:52:17
以下是使用 CSS 创建带有透明背景文字的图片的代码 −
示例
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" imageContent="width=device-width, initial-scale=1">
<style>
* {
box-sizing: border-box;
}
body {
font-family: Arial;
font-size: 17px;
}
.imageContainer {
display: inline-block;
position: relative;
}
.imageContainer .imageContent {
position: absolute;
bottom: 0;
background: rgba(29, 6, 43, 0.5); /* Black background with 0.5 opacity */
color: #f1f1f1;
width: 100%;
padding: 20px;
}
</style>
</head>
<body>
<h2>Image with Transparent Text</h2>
<div class="imageContainer">
<img src="https://i.picsum.photos/id/59/500/500.jpg">
<div class="imageContent">
<h1>Sceneray</h1>
<h3>A beautiful scenary showing fence, barbed wires and grass</h3>
</div>
</div>
</body>
</html>
输出
上述代码将产生以下输出 −

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

