2017-04-27 5 views
0

コンテナにカーソルを合わせると、背景の色がオーバーレイされ、transform: scale3d(1.1,1.1,1);を使って拡大縮小しようとしています。コンテナホバー上の背景の拡大イメージ

コードはインスペクタに表示されますが、有効にはなりません。

これは私が

.item:hover .img-container { 
    transform: scale3d(1.1,1.1,1); 
    -webkit-transform: scale3d(1.1,1.1,1); 
    -moz-transform: scale3d(1.1,1.1,1); 
    opacity: .2; 
} 

DEMOhttps://jsfiddle.net/xaw3vcL1/

HTML

<article class="item" style="background: url('https://images.pexels.com/photos/235470/pexels-photo-235470.jpeg?w=1260&h=750&auto=compress&cs=tinysrgb') center center/cover;"> 
    <div class="item-content"> 
    <a href="#" class="img-container"></a> 
    </div> 
    <div class="content-container"> 
    Title here 
    </div> 
</article> 

CSS

容器の上にカーソルを移動するたびに背景画像を拡大縮小することになっているCSSです
.item { 
    height: 450px; 
    position: relative; 
    overflow: hidden; 
} 

.item:before { 
    display: block; 
    content: " "; 
    width: 100%; 
    padding-top: 68.17%; 
} 

.item-content { 
    position: absolute!important; 
    top: 0; 
    left: 0; 
    right: 0; 
    bottom: 0; 
    overflow: hidden; 
} 

.img-container { 
    webkit-background-size: cover!important; 
    -moz-background-size: cover!important; 
    -o-background-size: cover!important; 
    background-size: cover!important; 
    position: absolute; 
    top: -1px; 
    left: -2px; 
    right: -2px; 
    bottom: -1px; 
    -webkit-transition: all .5s; 
    -moz-transition: all .5s; 
    transition: all .5s; 
    -webkit-backface-visibility: hidden; 
    backface-visibility: hidden; 
    -moz-transform-origin: 0 0; 
    transform: translate3d(0,0,0); 
} 

.img-container:after { 
    opacity: .5; 
    background: #26D0CE; 
    background: -moz-linear-gradient(45deg,#1A2980 0,#26D0CE 100%); 
    background: -webkit-gradient(left bottom,right top,color-stop(0,#1A2980),color-stop(100%,#26D0CE)); 
    background: -webkit-linear-gradient(45deg,#1A2980 0,#26D0CE 100%); 
    background: -o-linear-gradient(45deg,#1A2980 0,#26D0CE 100%); 
    background: -ms-linear-gradient(45deg,#1A2980 0,#26D0CE 100%); 
    background: linear-gradient(45deg,#1A2980 0,#26D0CE 100%); 
    -webkit-transition: all .35s ease; 
    -moz-transition: all .35s ease; 
    -o-transition: all .35s ease; 
    transition: all .35s ease; 
    content: ''; 
    position: absolute; 
    top: 0; 
    left: 0; 
    right: 0; 
    bottom: 0; 
} 

.item:hover .img-container { 
    transform: scale3d(1.1,1.1,1); 
    -webkit-transform: scale3d(1.1,1.1,1); 
    -moz-transform: scale3d(1.1,1.1,1); 
    opacity: .2; 
} 

.content-container { 
    position: absolute; 
    bottom: 15px; 
    left: 20px; 
    right: 20px; 
    padding: 0; 
    max-height: 75%; 
    overflow: hidden; 
    pointer-events: none; 
    transform: translate3d(0,0,0); 
    -webkit-backface-visibility: hidden; 
} 

答えて

2

背景画像がimg-containerではなく、article.itemに設定されているため、背景画像が機能しません。

コードを機能させるには、背景画像を適切なコンテナに配置する必要があります。

と、.item:hover .img-containerからopacity:.2を削除し、

が見.item:hover .img-container:after {opacity:.2}は、スニペットの追加や

.item { 
 
    height: 450px; 
 
    position: relative; 
 
    overflow: hidden; 
 
} 
 

 
.item:before { 
 
    display: block; 
 
    content: " "; 
 
    width: 100%; 
 
    padding-top: 68.17%; 
 
} 
 

 
.item-content { 
 
    position: absolute!important; 
 
    top: 0; 
 
    left: 0; 
 
    right: 0; 
 
    bottom: 0; 
 
    overflow: hidden; 
 
} 
 

 
.img-container { 
 
    webkit-background-size: cover!important; 
 
    -moz-background-size: cover!important; 
 
    -o-background-size: cover!important; 
 
    background-size: cover!important; 
 
    position: absolute; 
 
    top: -1px; 
 
    left: -2px; 
 
    right: -2px; 
 
    bottom: -1px; 
 
    -webkit-transition: all .5s; 
 
    -moz-transition: all .5s; 
 
    transition: all .5s; 
 
    -webkit-backface-visibility: hidden; 
 
    backface-visibility: hidden; 
 
    -moz-transform-origin: 0 0; 
 
    transform: translate3d(0,0,0); 
 
} 
 

 
.img-container:after { 
 
    opacity: .5; 
 
    background: #26D0CE; 
 
    background: -moz-linear-gradient(45deg,#1A2980 0,#26D0CE 100%); 
 
    background: -webkit-gradient(left bottom,right top,color-stop(0,#1A2980),color-stop(100%,#26D0CE)); 
 
    background: -webkit-linear-gradient(45deg,#1A2980 0,#26D0CE 100%); 
 
    background: -o-linear-gradient(45deg,#1A2980 0,#26D0CE 100%); 
 
    background: -ms-linear-gradient(45deg,#1A2980 0,#26D0CE 100%); 
 
    background: linear-gradient(45deg,#1A2980 0,#26D0CE 100%); 
 
    -webkit-transition: all .35s ease; 
 
    -moz-transition: all .35s ease; 
 
    -o-transition: all .35s ease; 
 
    transition: all .35s ease; 
 
    content: ''; 
 
    position: absolute; 
 
    top: 0; 
 
    left: 0; 
 
    right: 0; 
 
    bottom: 0; 
 
} 
 

 
.item:hover .img-container { 
 
    transform: scale3d(1.1,1.1,1); 
 
    -webkit-transform: scale3d(1.1,1.1,1); 
 
    -moz-transform: scale3d(1.1,1.1,1); 
 
} 
 
.item:hover .img-container:after { 
 
\t opacity:.2 
 
} 
 

 
.content-container { 
 
    position: absolute; 
 
    bottom: 15px; 
 
    left: 20px; 
 
    right: 20px; 
 
    padding: 0; 
 
    max-height: 75%; 
 
    overflow: hidden; 
 
    pointer-events: none; 
 
    transform: translate3d(0,0,0); 
 
    -webkit-backface-visibility: hidden; 
 
}
<article class="item" > 
 
    <div class="item-content"> 
 
    <a href="#" class="img-container" style="background: url('https://images.pexels.com/photos/235470/pexels-photo-235470.jpeg?w=1260&h=750&auto=compress&cs=tinysrgb') center center/cover;"></a> 
 
    </div> 
 
    <div class="content-container"> 
 
    Title here 
 
    </div> 
 
</article>

+0

これは素晴らしいです、ありがとう。しかし、あなたが私に尋ねる気にならないなら、なぜ私が選んだ色の代わりに、私がそれの上にマウスを置いたときに白い背景を得るのですか? – Halnex

+0

白い背景は、不透明度のために0.2:HOVERであり、 'item'の下の背景は灰色/白(デフォルトの背景の背景)です。そして ':after'は不透明度0.2を与える同じ項目に設定されているので、そのスタイルも取得します。したがって、 ':after'を' img-container'ではなく 'item'に設定してください。https://jsfiddle.net/xaw3vcL1/3/ –

+0

これは別の問題を追加します。背景画像を正しく表示したい白い背景があればそれはさらに曖昧になります。私の元のコードと同様に、その上にマウスを置くと画像がより鮮明になります。 – Halnex

-1

jsFiddleあなたのCSSに、このクラスを追加

article:hover{transform: scale3d(1.1,1.1,1); 
-webkit-transform: scale3d(1.1,1.1,1); 
-moz-transform: scale3d(1.1,1.1,1); 
opacity:0.2;} 
関連する問題