AI(ChatGPT)を使って半自動で月5万稼ぐ?
実際にやってみて結果・・ >>

【Web制作に最適】背景を重ねるCSS画像アニメーション4選

今回は【Web制作に最適】背景を重ねるCSS画像アニメーション4選をご紹介。シンプルかつ洗練されたデザイン。それぞれ違うエフェクトと滑らかな動き。Web制作で使える。ポートフォリオにも最適。コピペOK。HTML, CSSだけ
動きを見ていただければ使いたくなること間違いなしです!

コードの説明や実際の動きも詳しくまとめてみたので自由にお使いください。

こちらのデザイン・コードはすべて完全オリジナルなのでコピペ大歓迎です。

Webデザインやフロントエンド初心者の方はWebデザイナー3ヶ月独学ロードマップを読んでから学習してもらえれば失敗しないと思います。

ふたご

 

1. 半分の背景が左右から現れるCSS画像アニメーション

動きは下の画像のような感じになります

コードを見る
  <div class="container">
    <!-- 画像と背景・文字を複数配置 -->
    <div class="bg-pic">
      <div class="pic" style="background-image : url('https://cdn.pixabay.com/photo/2017/01/17/23/05/valetta-1988455_1280.jpg');">
        <div class="screen one"></div>
        <!-- 背景1段目 -->
        <div class="screen two"></div>
        <!-- 背景2段目 -->
        <div class="fonts">
          <h1>Malta's Building</h1>
          <p>this is a photo in malta <br><br><br>Have A Good Time</p>
        </div>
      </div>
    </div>
    <div class="bg-pic">
      <div class="pic" style="background-image : url('https://images.unsplash.com/photo-1551607117-21fa129a211d?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1720&q=80');">
        <div class="screen one"></div>
        <!-- 背景1段目 -->
        <div class="screen two"></div>
        <!-- 背景2段目 -->
        <div class="fonts">
          <h1>Malta's Building</h1>
          <p>this is a photo in malta <br><br><br>Have A Good Time</p>
        </div>
      </div>
    </div>
    <div class="bg-pic">
      <div class="pic" style="background-image : url('https://images.unsplash.com/photo-1519221739757-4df89b4d0efe?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1650&q=80');">
        <div class="screen one"></div>
        <!-- 背景1段目 -->
        <div class="screen two"></div>
        <!-- 背景2段目 -->
        <div class="fonts">
          <h1>Malta's Building</h1>
          <p>this is a photo in malta <br><br><br>Have A Good Time</p>
        </div>
      </div>
    </div>
  </div>
/* 要素全体のサイズ・配置を指定 */
.container {
  width  : 100%;
  margin-top: 30px;
  display: flex;
  align-items:center;
  justify-content:center;
}
.container:after{
  clear   : both;
  display : table;
  content : '';
}
.bg-pic {
  width  : 440px;
  height : 300px;
  background-color: white;
  cursor : pointer;
}
.pic {
  /* 画像が美しく見えるようにエフェクト(明るさ・コントラスト・彩度)を調整 */
  filter: brightness(110%) contrast(105%) saturate(120%);
  width  : 440px;
  height : 300px;
  /* 相対的位置を指定 */
  position: relative;
  /* 枠に収まらない要素を隠す指定 */
  overflow: hidden;
  background-color: #102B46;
  background-size: cover;
  /* .pic全体に画像が表示されるように指定 */
}
/* ↓hover後に浮き出てくる文字と背景の設定 */
.fonts {
  text-align: center;
  background-color : #ffffff;
  width            : 440px;
  height           : 300px;
  padding          : 10px;
  top : 0;
  left: 0;
  color       : #888888;
  /* hover前のの文字の不透明度を指定 */
  opacity : 0;
  transition : opacity .8s;
  /* hover後カーソルを外した際に文字と背景が消える時間を指定 */
}
.fonts h1 {
  font-size: 28px;
  margin-top: 50px;
  margin-bottom : 40px;
}
.fonts p {
  font-size : 14px;
  font-style: italic;
  text-align: center;
  line-height : 20px;
}
.pic:hover .fonts {
  /* hover後の文字の不透明度を指定 */
  opacity : 1;
  transition : opacity .5s .3s;
  /* hover後に文字と背景が現れる時間を指定 */
}
.pic div {
  position : absolute;
  /* .pic div(hover後に現れる文字と背景)の位置を指定 */
}
.screen {
  /* スクリーン全体のスタイル設定 */
  width  : inherit;
  height : 150px;
  /* 背景の高さを指定 */
  background-color: #fff;
}
.screen.one {
  /* スクリーン1のスタイル設定 */
  top : 0;
  left: 100%;
  transition : all .4s .2s;
  /* 背景が消える速度調整 */
}
.screen.two {
  /* スクリーン2のスタイル設定 */
  top : 150px;
  right: 100%;
  transition : all .4s .2s;
  /* 背景が消える速度調整 */
}
.pic:hover .one {
  /* hover後のスクリーン1のスタイル設定 */
  left : 0;
  /* 背景が現れる始める位置指定 */
  transition : all .4s;
  /* 背景が現れる速度調整 */
}
.pic:hover .two {
  /* hover後のスクリーン2のスタイル設定 */
  right : 0;
  /* 背景が現れる始める位置指定 */
  transition : all .4s;
  /* 背景が現れる速度調整 */
}
ここがポイント!
  1. display : flexで画像を複数横並びに配置
  2. .picにoverflow: hiddenを設定することで収まらない要素を隠す
  3. screenに背景のアニメーションスタート位置を指定
  4. 画像の配置を固定するためpicクラスにposition:relative, picクラスのdivタグにposition:absoluteを指定
  5. 背景が左右から半分ずつ現れるように表示させるため2つのscreenクラスで異なる位置・速度を指定
  6. 各transitionプロパティをhover前・hover後に指定することで滑らかなアニメーションを実現

 

2. 背景が両斜めから現れるCSS画像アニメーション

動きは下の画像のような感じになります

コードを見る
  <div class="container">
    <!-- 画像と背景・文字を複数配置 -->
    <div class="bg-pic">
      <div class="pic" style="background-image : url('https://cdn.pixabay.com/photo/2017/01/17/23/05/valetta-1988455_1280.jpg');">
        <div class="screen one"></div>
        <!-- 背景1段目 -->
        <div class="screen two"></div>
        <!-- 背景2段目 -->
        <div class="fonts">
          <h1>Malta's Building</h1>
          <p>this is a photo in malta <br><br><br>Have A Good Time</p>
        </div>
      </div>
    </div>
    <div class="bg-pic">
      <div class="pic" style="background-image : url('https://images.unsplash.com/photo-1551607117-21fa129a211d?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1720&q=80');">
        <div class="screen one"></div>
        <!-- 背景1段目 -->
        <div class="screen two"></div>
        <!-- 背景2段目 -->
        <div class="fonts">
          <h1>Malta's Building</h1>
          <p>this is a photo in malta <br><br><br>Have A Good Time</p>
        </div>
      </div>
    </div>
    <div class="bg-pic">
      <div class="pic" style="background-image : url('https://images.unsplash.com/photo-1519221739757-4df89b4d0efe?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1650&q=80');">
        <div class="screen one"></div>
        <!-- 背景1段目 -->
        <div class="screen two"></div>
        <!-- 背景2段目 -->
        <div class="fonts">
          <h1>Malta's Building</h1>
          <p>this is a photo in malta <br><br><br>Have A Good Time</p>
        </div>
      </div>
    </div>
  </div>
/* 要素全体のサイズ・配置を指定 */
.container {
  width  : 100%;
  margin-top: 30px;
  display: flex;
  align-items:center;
  justify-content:center;
}
.container:after{
  clear   : both;
  display : table;
  content : '';
}
.bg-pic {
  width  : 440px;
  height : 300px;
  background-color: white;
  cursor : pointer;
}
.pic {
  /* 画像が美しく見えるようにエフェクト(明るさ・コントラスト・彩度)を調整 */
  filter: brightness(110%) contrast(105%) saturate(120%);
  width  : 440px;
  height : 300px;
  /* 相対的位置を指定 */
  position: relative;
  /* 枠に収まらない要素を隠す指定 */
  overflow: hidden;
  background-color: #102B46;
  background-size: cover;
  /* .pic全体に画像が表示されるように指定 */
}
/* ↓hover後に浮き出てくる文字と背景の設定 */
.fonts {
  text-align: center;
  background-color : #ffffff;
  width            : 440px;
  height           : 300px;
  padding          : 10px;
  top : 0;
  left: 0;
  color       : #888888;
  /* hover前のの文字の不透明度を指定 */
  opacity : 0;
  transition : opacity .8s;
  /* hover後カーソルを外した際に文字と背景が消える時間を指定 */
}
.fonts h1 {
  font-size: 28px;
  margin-top: 50px;
  margin-bottom : 40px;
}
.fonts p {
  font-size : 14px;
  font-style: italic;
  text-align: center;
  line-height : 20px;
}
.pic:hover .fonts {
  /* hover後の文字の不透明度を指定 */
  opacity : 1;
  transition : opacity .2s .3s;
  /* hover後に文字と背景が現れる時間を指定 */
}
.pic div {
  position : absolute;
  /* .pic div(hover後に現れる文字と背景)の位置を指定 */
}
.screen {
  /* スクリーン全体のスタイル設定 */
  width : inherit;
  height: inherit;
  /* 背景の高さを指定 */
  background-color: #fff;
  transition : all .3s;
}
.screen.one {
  transition : all .3s .3s;
  /* 背景が消える速度調整 */
  left   : 100%;
  bottom : 100%;
  /* 背景のアニメーションスタート位置指定 */
}
.screen.two {
  transition : all .3s .3s;
  /* 背景が消える速度調整 */
  right   : 100%;
  top : 100%;
  /* 背景のアニメーションスタート位置指定 */
}
.pic:hover .one {
  left   : 0;
  bottom : 0;
  /* hover後の背景の位置指定 */
  transition : all .6s;
  /* 背景が現れる速度調整 */
}
.pic:hover .two {
  right  : 0;
  top : 0;
  /* hover後の背景の位置指定 */
  transition : all .6s;
  /* 背景が現れる速度調整 */
}
ここがポイント!
  1. display : flexで画像を複数横並びに配置
  2. .picにoverflow: hiddenを設定することで収まらない要素を隠す
  3. screenに背景のアニメーションスタート位置を指定
  4. 画像の配置を固定するためpicクラスにposition:relative, picクラスのdivタグにposition:absoluteを指定
  5. 背景が両斜めから現れるように表示させるため2つのscreenクラスで位置・速度を指定
  6. 各transitionプロパティをhover前・hover後に指定することで滑らかなアニメーションを実現

 

3. 背景が上下から現れる自動ドアのようなCSS画像アニメーション

動きは下の画像のような感じになります

コードを見る
  <div class="container">
    <!-- 画像と背景・文字を複数配置 -->
    <div class="bg-pic">
      <div class="pic" style="background-image : url('https://cdn.pixabay.com/photo/2017/01/17/23/05/valetta-1988455_1280.jpg');">
        <div class="screen one"></div>
        <!-- 背景1段目 -->
        <div class="screen two"></div>
        <!-- 背景2段目 -->
        <div class="fonts">
          <h1>Malta's Building</h1>
          <p>this is a photo in malta <br><br><br>Have A Good Time</p>
        </div>
      </div>
    </div>
    <div class="bg-pic">
      <div class="pic" style="background-image : url('https://images.unsplash.com/photo-1551607117-21fa129a211d?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1720&q=80');">
        <div class="screen one"></div>
        <!-- 背景1段目 -->
        <div class="screen two"></div>
        <!-- 背景2段目 -->
        <div class="fonts">
          <h1>Malta's Building</h1>
          <p>this is a photo in malta <br><br><br>Have A Good Time</p>
        </div>
      </div>
    </div>
    <div class="bg-pic">
      <div class="pic" style="background-image : url('https://images.unsplash.com/photo-1519221739757-4df89b4d0efe?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1650&q=80');">
        <div class="screen one"></div>
        <!-- 背景1段目 -->
        <div class="screen two"></div>
        <!-- 背景2段目 -->
        <div class="fonts">
          <h1>Malta's Building</h1>
          <p>this is a photo in malta <br><br><br>Have A Good Time</p>
        </div>
      </div>
    </div>
  </div>
/* 要素全体のサイズ・配置を指定 */
.container {
  width  : 100%;
  margin-top: 30px;
  display: flex;
  align-items:center;
  justify-content:center;
}
.container:after{
  clear   : both;
  display : table;
  content : '';
}
.bg-pic {
  width  : 440px;
  height : 300px;
  background-color: white;
  cursor : pointer;
}
.pic {
  /* 画像が美しく見えるようにエフェクト(明るさ・コントラスト・彩度)を調整 */
  filter: brightness(110%) contrast(105%) saturate(120%);
  width  : 440px;
  height : 300px;
  /* 相対的位置を指定 */
  position: relative;
  /* 枠に収まらない要素を隠す指定 */
  overflow: hidden;
  background-color: #102B46;
  background-size: cover;
  /* .pic全体に画像が表示されるように指定 */
}
/* ↓hover後に浮き出てくる文字と背景の設定 */
.fonts {
  text-align: center;
  background-color : #ffffff;
  width            : 440px;
  height           : 300px;
  padding          : 10px;
  top : 0;
  left: 0;
  color       : #888888;
  /* hover前のの文字の不透明度を指定 */
  opacity : 0;
  transition : opacity .8s;
  /* hover後カーソルを外した際に文字と背景が消える時間を指定 */
}
.fonts h1 {
  font-size: 28px;
  margin-top: 50px;
  margin-bottom : 40px;
}
.fonts p {
  font-size : 14px;
  font-style: italic;
  text-align: center;
  line-height : 20px;
}
.pic:hover .fonts {
  /* hover後の文字の不透明度を指定 */
  opacity : 1;
  transition : opacity .2s .3s;
  /* hover後に文字と背景が現れる時間を指定 */
}
.pic div {
  position : absolute;
  /* .pic div(hover後に現れる文字と背景)の位置を指定 */
}
.screen {
  /* スクリーン全体のスタイル設定 */
  width  : inherit;
  height : 150px;
  /* 背景の高さを指定 */
  background-color: #fff;
  transition : all .3s;
}
.screen.one {
  transition : all .3s .1s;
  /* 背景が消える速度調整 */
  top : -150px;
  /* 背景のアニメーションスタート位置指定 */
}
.screen.two {
  transition : all .3s .1s;
  /* 背景が消える速度調整 */
  bottom : -150px;
  /* 背景のアニメーションスタート位置指定 */
}
.pic:hover .one {
  top : 0px;
  /* hover後の背景の位置指定 */
  transition : all .3s;
  /* 背景が現れる速度調整 */
}
.pic:hover .two {
  bottom : 0px;
  /* hover後の背景の位置指定 */
  transition : all .3s;
  /* 背景が現れる速度調整 */
}
ここがポイント!
  1. display : flexで画像を複数横並びに配置
  2. .picにoverflow: hiddenを設定することで収まらない要素を隠す
  3. screenに背景のアニメーションスタート位置を指定
  4. 画像の配置を固定するためpicクラスにposition:relative, picクラスのdivタグにposition:absoluteを指定
  5. 上下から背景が現れて自動ドアのように表示させるため2つのscreenクラスで異なる位置・速度を指定
  6. 各transitionプロパティをhover前・hover後に指定することで滑らかなアニメーションを実現

 

4. 半分の背景が上下から現れるCSS画像アニメーション

動きは下の画像のような感じになります

コードを見る
  <div class="container">
    <!-- 画像と背景・文字を複数配置 -->
    <div class="bg-pic">
      <div class="pic" style="background-image : url('https://cdn.pixabay.com/photo/2017/01/17/23/05/valetta-1988455_1280.jpg');">
        <div class="screen one"></div>
        <!-- 背景1段目 -->
        <div class="screen two"></div>
        <!-- 背景2段目 -->
        <div class="fonts">
          <h1>Malta's Building</h1>
          <p>this is a photo in malta <br><br><br>Have A Good Time</p>
        </div>
      </div>
    </div>
    <div class="bg-pic">
      <div class="pic" style="background-image : url('https://images.unsplash.com/photo-1551607117-21fa129a211d?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1720&q=80');">
        <div class="screen one"></div>
        <!-- 背景1段目 -->
        <div class="screen two"></div>
        <!-- 背景2段目 -->
        <div class="fonts">
          <h1>Malta's Building</h1>
          <p>this is a photo in malta <br><br><br>Have A Good Time</p>
        </div>
      </div>
    </div>
    <div class="bg-pic">
      <div class="pic" style="background-image : url('https://images.unsplash.com/photo-1519221739757-4df89b4d0efe?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1650&q=80');">
        <div class="screen one"></div>
        <!-- 背景1段目 -->
        <div class="screen two"></div>
        <!-- 背景2段目 -->
        <div class="fonts">
          <h1>Malta's Building</h1>
          <p>this is a photo in malta <br><br><br>Have A Good Time</p>
        </div>
      </div>
    </div>
  </div>
/* 要素全体のサイズ・配置を指定 */
.container {
  width  : 100%;
  margin-top: 30px;
  display: flex;
  align-items:center;
  justify-content:center;
}
.container:after{
  clear   : both;
  display : table;
  content : '';
}
.bg-pic {
  width  : 440px;
  height : 300px;
  background-color: white;
  cursor : pointer;
}
.pic {
  /* 画像が美しく見えるようにエフェクト(明るさ・コントラスト・彩度)を調整 */
  filter: brightness(110%) contrast(105%) saturate(120%);
  width  : 440px;
  height : 300px;
  /* 相対的位置を指定 */
  position: relative;
  /* 枠に収まらない要素を隠す指定 */
  overflow: hidden;
  background-color: #102B46;
  background-size: cover;
  /* .pic全体に画像が表示されるように指定 */
}
/* ↓hover後に浮き出てくる文字と背景の設定 */
.fonts {
  text-align: center;
  background-color : #ffffff;
  width            : 440px;
  height           : 300px;
  padding          : 10px;
  top : 0;
  left: 0;
  color       : #888888;
  /* hover前のの文字の不透明度を指定 */
  opacity : 0;
  transition : opacity .8s;
  /* hover後カーソルを外した際に文字と背景が消える時間を指定 */
}
.fonts h1 {
  font-size: 28px;
  margin-top: 50px;
  margin-bottom : 40px;
}
.fonts p {
  font-size : 14px;
  font-style: italic;
  text-align: center;
  line-height : 20px;
}
.pic:hover .fonts {
  /* hover後の文字の不透明度を指定 */
  opacity : 1;
  transition : opacity .2s .3s;
  /* hover後に文字と背景が現れる時間を指定 */
}
.pic div {
  position : absolute;
  /* .pic div(hover後に現れる文字と背景)の位置を指定 */
}
.screen {
  /* スクリーン全体のスタイル設定 */
  width  : inherit;
  height : 300px;
  /* 背景の高さを指定 */
  background-color: #fff;
  transition : all .3s;
}
.screen.one {
  transition : all .3s .2s;
  /* 背景が消える速度調整 */
  left: 50%;
  top : -300px;
  /* 背景のアニメーションスタート位置指定 */
}
.screen.two {
  transition : all .3s .2s;
  /* 背景が消える速度調整 */
  right: 50%;
  bottom : -300px;
  /* 背景のアニメーションスタート位置指定 */
}
.pic:hover .one {
  top : 0px;
  /* hover後の背景の位置指定 */
  transition : all .4s;
  /* 背景が現れる速度調整 */
}
.pic:hover .two {
  bottom : 0px;
  /* hover後の背景の位置指定 */
  transition : all .4s;
  /* 背景が現れる速度調整 */
}
ここがポイント!
  1. display : flexで画像を複数横並びに配置
  2. .picにoverflow: hiddenを設定することで収まらない要素を隠す
  3. screenに背景のアニメーションスタート位置を指定
  4. 画像の配置を固定するためpicクラスにposition:relative, picクラスのdivタグにposition:absoluteを指定
  5. 上下から背景を半分ずつ表示させるため2つのscreenクラスで位置・速度を指定
  6. 各transitionプロパティをhover前・hover後に指定することで滑らかなアニメーションを実現

参考

そもそもWebデザインの基礎がわからない。。
そんなあなたにはこれ!

ふたご


でもなあ、独学だと心配だしプログラミングスクールで学びたい!。かといってお金はかけたくないし。。
そんなあなたにはこれ!

ふたご

完全無料で一人前のエンジニアになれるプログラミングスクールあります
  1. プログラミング学習&サポートが無料!
  2. 誰もが知っている超優良企業への就職サポート付き!
  3. 学習言語:Java、PHP、HTML、CSSなど

 

   話だけ聞いてみる