LoginSignup
9
6

More than 5 years have passed since last update.

簡単に画像Aに画像Bを上書きする方法

Posted at

画像Aに画像Bを上書きする方法についてです。
色んな方法がありますが、私が好きな方法を紹介します。

hoge.html
<div class="relative">
  <img src="A.jpg">
  <img src="B.jpg" id="uwagaki">
</div>

画像Aと画像Bをdivでくるみます。

hoge.css
#uwagaki {
    position: absolute;
    top:0;
    left:0;
}
.relative {
    position: relative;
}

次にcssでpositionをうまく使って、画像を重ねます。
画像Aと画像Bのサイズが同じ場合, これだけでピッタリと上書きさせることができます.

画像Bでposition:relative;を使うと画像の分のスペースが空いてしまうので注意.

この方法はbootstrapで書いている場合でもちゃんと上書きしてくれます.

9
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
6