見出し
Lorem ipsum dolor sit amet, an his etiam torquatos.
CSSを使用して透明(半透明)背景のテキストを持つ画像を作成する方法を学びます。
Lorem ipsum dolor sit amet, an his etiam torquatos.
<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; /* 一定のインセット */ }