标题
Lorem ipsum dolor sit amet, an his etiam torquatos.
了解如何使用 CSS 创建带有透明(半透明)背景文本的图像。
Lorem ipsum dolor sit amet, an his etiam torquatos. Tollit soleat phaedrum te duo, eum cu recteque expetendis neglegentur. Cu mentitum maiestatis persequeris pro, pri ponderum tractatos ei.
<div class="container">
<img src="notebook.jpg" alt="笔记本" style="width:100%;">
<div class="content">
<h1>标题</h1>
<p>Lorem ipsum..</p>
</div>
</div>
.container {
position: relative;
max-width: 800px; /* 最大宽度 */
margin: 0 auto; /* 居中 */
}
.container .content {
position: absolute; /* 定位背景文本 */
bottom: 0; /* 在底部。使用 top:0 将其附加到顶部 */
background: rgb(0, 0, 0); /* 备用颜色 */
background: rgba(0, 0, 0, 0.5); /* 黑色背景,不透明度为 0.5 */
color: #f1f1f1; /* 灰色文本 */
width: 100%; /* 全宽 */
padding: 20px; /* 填充一些间距 */
}
自己试一试 »
If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
[email protected]
If you want to report an error, or if you want to make a suggestion, send us an e-mail:
[email protected]