方法-画像上のテキストブロック
画像の上にテキストブロックを配置する方法を学びます。
画像テキストブロック
画像にテキストブロックを配置する方法
ステップ1)HTMLを追加します。
例
<div class="container">
<img src="nature.jpg" alt="Norway"
style="width:100%;">
<div class="text-block">
<h4>Nature</h4>
<p>What a beautiful sunrise</p>
</div>
</div>
ステップ2)CSSを追加します。
例
/* Container holding the image and the text */
.container {
position: relative;
}
/* Bottom right text */
.text-block {
position: absolute;
bottom: 20px;
right: 20px;
background-color: black;
color: white;
padding-left: 20px;
padding-right: 20px;
}
画像のスタイルを設定する方法の詳細については、CSS画像のチュートリアルをご覧ください。
CSSポジショニングの詳細については、 CSS位置チュートリアルをお読みください。