2017-11-27 2 views
0

私のセクションには背景画像がありますが、画面幅が768pxを超えると、この画像を応答可能な背景ビデオに変更する必要があります。私はメディアクエリでこれを行うことができますが、bgイメージを応答可能なbgビデオに変更する方法は知っていますか?次のようにバックグラウンド画像をバックグラウンドビデオに変更するには、ブートストラップ4で画面サイズに基づいて可能性があります

私のコードは次のとおりです。

.welcome { 
 
     height: 100vh; 
 
     background: url("../images/welcome-bg.png") no-repeat center center; 
 
     background-size: cover; 
 
    }
<section class="d-flex welcome align-items-center"> 
 
     <div class="container-fluid"> 
 
      <h1 class="welcome-text">Welcome To Kramerica Industries</h1> 
 
      <div class="explore-container"> 
 
       <a class="v-explore-button" href="#about">V</a> 
 
       <p class="explore-text">Explore</p> 
 
      </div> 
 
     </div> 
 
    </section>

+0

「bgイメージを応答可能なbgビデオに変更する方法」とはどういう意味ですか? –

+0

セクションの背景に768px以下の画面幅がある場合、私は応答性のある背景イメージを持っています。しかし、画面の幅がセクションの背景で768px以上になると、私はレスポンシブな背景ビデオを持つ必要があります。 – Belial

+0

したがって、画面サイズに基づいて、画像とビデオを切り替える、つまり画面サイズが<768の場合は画像を表示し、それ以外の場合は画像を右に表示しますか? –

答えて

0

は、あなたが2つのdivを、クラスdivImageとビデオは、以下のような何かをよりクラスdivVideoを持つための1つを有する画像のための1つを持っていると仮定しましょう:

@media (max-width: 768px) 
 
     { 
 
      .welcome { 
 
      height: 100vh; 
 
      background: url("../images/welcome-bg.png") no-repeat center center; 
 
      background-size: cover; 
 
    } 
 
      video { 
 
      display:none; 
 
      } 
 
     
 
     } 
 
     @media (min-width: 769px) and (max-width : 1024px) { 
 
      .welcome { 
 
      height: 0vh; 
 
      background: url("") no-repeat center center; 
 
      
 
    } 
 
      video { 
 
       display:block; 
 
      } 
 
     }
<section class="d-flex welcome align-items-center"> 
 

 
<!-- Video Tag Here --> 
 
    <video id="bgVideo" autoplay loop poster="image.png"> 
 
     <!-- Video is embedded in the WEBM format --> 
 
     <source src="video.webm" type="video/webm"> 
 
    </video> 
 

 
     <div class="container-fluid"> 
 
      <h1 class="welcome-text">Welcome To Kramerica Industries</h1> 
 
      <div class="explore-container"> 
 
       <a class="v-explore-button" href="#about">V</a> 
 
       <p class="explore-text">Explore</p> 
 
      </div> 
 
     </div> 
 
    </section>

+0

セクションに背景画像がある場合、これを行うことはできますか?または、背景画像と背景ビデオのセクション内に2つのdivを作成する必要がありますか? – Belial

+0

まず、あなたのセクションにビデオをどのように表示していますか?画像とビデオの両方にHTMLを表示する –

+0

自分のコードをすべて追加しました。私のセクションに背景ビデオを追加する方法がわからないので、ここで質問してください。 – Belial

関連する問題