2016-05-16 8 views
9

私は、このクリエイティブに近づけるように、斜めのdivに部分的な影を作成しようとしています。斜めのdivに部分的なボックスの影を作成する

enter image description here

今私は(特に前の)擬似要素でこれをやろうとしてきたが、私は彼らが適用されている要素を歪曲するたびに、それらの要素が奇妙な動作ことがわかりました。 z-indexが-1に設定されていても、疑似要素はdivの上に表示され続けます。私がz-indexを使って何をしても、それはその上にとどまります。私はそれが適用されているdivの下にあり、下のdivの前に、クリエイティブのようにしたい。

enter image description here

はここにある、それは完璧ではないですが、私のコードの前に::、私が試してみました

/*! Shadows */ 
#test-title { 
    position: relative; 
} 

#test-title:before { 
    z-index: -1; 
    position: absolute; 
    content: ""; 
    bottom: 15px; 
    left: 10px; 
    width: 50%; 
    top: 80%; 
    max-width:300px; 
    box-shadow: 0 15px 10px #777; 
    -webkit-transform: rotate(-3deg); 
    -moz-transform: rotate(-3deg); 
    -o-transform: rotate(-3deg); 
    -ms-transform: rotate(-3deg); 
    transform: rotate(-3deg); 
} 

http://codepen.io/kathryncrawford/pen/WwWEma

答えて

9

Skew親を使用して、第2の要素のボックスシャドウを作成してみてください。かなりいいです

* { 
 
    box-sizing: border-box 
 
} 
 
body { 
 
    padding: 40px 0 
 
} 
 
section { 
 
    width: 60vw; 
 
    clear: both; 
 
    overflow: hidden; 
 
    min-height: 100px; 
 
    margin: 0 auto; 
 
    position: relative; 
 
    background: #035076 
 
} 
 
section article { 
 
    width: 60%; 
 
    padding: 20px; 
 
    color: white; 
 
    margin: 0 auto 
 
} 
 
section:nth-child(even) { 
 
    transform: skew(-45deg) translate(5vw); 
 
    box-shadow: inset 0 0 2px 0 black; 
 
} 
 
section:nth-child(odd) { 
 
    transform: skew(45deg); 
 
} 
 
section:nth-child(even) article { 
 
    transform: skew(45deg) translate(5vw); 
 
} 
 
section:nth-child(odd) article { 
 
    transform: skew(-45deg); 
 
} 
 
section:before, 
 
section:after { 
 
    content: ''; 
 
    position: absolute; 
 
} 
 
section:nth-child(even):before { 
 
    width: 100%; 
 
    height: 0; 
 
    bottom: 100%; 
 
    left: 0; 
 
    z-index: 6; 
 
    opacity: 1; 
 
    transform: rotate(-10deg) translateY(-30px); 
 
    box-shadow: 0px 0px 64px 30px rgba(0, 0, 0, 0.8); 
 
} 
 

 
section:nth-child(odd):not(:first-child):before { 
 
    width: 100%; 
 
    height: 0; 
 
    bottom: 100%; 
 
    right: 0; 
 
    z-index: 6; 
 
    opacity: 1; 
 
    transform: rotate(10deg) translateY(-30px); 
 
    box-shadow: 0px 0px 64px 30px rgba(0, 0, 0, 0.8); 
 
}
<section> 
 
    <article>What our clients say About Us</article> 
 
</section> 
 
<section> 
 
    <article>Read More!</article> 
 
</section> 
 
<section> 
 
    <article>Read More!</article> 
 
</section> 
 
<section> 
 
    <article>Read More!</article> 
 
</section>

+1

うわー、これは完璧です。ありがとう! –

+0

あなたは歓迎です:) –

0

codepen

CSSへのリンクですが、所望の外観に近いimho:

<div id="test-title"> 
      <h3>What our clients say about us</h3> 
     </div> 
     <div id="shadow1"></div> 

擬似要素を使用するのではなく、新しいhtml要素(シャドウ)を追加しました...今、最初のdivの後ろの回転シャドウdivを非表示にするためにz-インデックスと位置を正しく設定し、追加しましたこのCSS:

#shadow1 { 
    position:absolute; 
    width:50%; 
    height:150px; 
    background:black; 
    top:50px; 
    left:11%; 
    z-index:6; 
    opacity:1; 
transform: rotate(-5deg); 
box-shadow: 15px 56px 50px -12px rgba(0,0,0,0.80); 

} 

デモ:http://codepen.io/anon/pen/vGwNqY

あなたが回転、ボックスシャドウ、位置、高さと遊ぶことができる...しかし、これは(多分)良いスタートである可能性があります。 P.S. 2番目のdivにも同様のロジックを適用できます。

2

簡単なアプローチは、最初の後に各ボックスの上部にドロップシャドウを置くことです。これは、各ボックスがその上のボックスよりも1レベル上にあるので、あらゆる種類のZインデックス問題を解決します。そして、シャドウは、その外側ではなくコンテナの内側に座ることができます。

また、シャドースタイリングでは、ボックスシャドーの代わりに放射状のグラデーション*を使用するように変更しました。これは、この状況ではやや制御しやすく、デザインにも近いものです。私はこれまで、あなたの最後のルールセットを変更しましたskew1skew2

私はまた、それがあまりにも少し良く見えるように、とのために別の側面を取得する位置のビットをした:

.test-info:before { 
    position: absolute; 
    content: ""; 
    width: 100%; 
    left: 0; 
    top: 0; 
    height: 30px; 
} 

.test-info.skew1:before { 
    background: radial-gradient(ellipse farthest-side at 30% top, rgba(0,0,0,0.5) 0%, rgba(0,0,0,0) 100%); 
} 
.test-info.skew2:before { 
    background: radial-gradient(ellipse farthest-side at 70% top, rgba(0,0,0,0.5) 0%, rgba(0,0,0,0) 100%); 
} 

See Demo

* note:使用する前に入力したグラデーションで追加のブラウザサポートを確認/追加することができます。

+0

! –

0

は同程度で子unskewその後、:before擬似https://jsfiddle.net/0andpzsp/

.cont { 
 
    width: 1000px; 
 
    height: 500px; 
 
} 
 

 
div[class^="d"] { 
 
    width: 70%; 
 
    height: 50%; 
 
    position: relative; 
 
    margin-left: 40px; 
 
    margin-top: 50px; 
 
} 
 

 
.d0 { 
 
    background: linear-gradient(to right, #005f8a 0%,#00486c 50%,#003a59 100%);; 
 
    transform: skew(20deg) 
 
} 
 

 
.d1 { 
 
    background: linear-gradient(to right, #005f8a 0%,#00486c 50%,#003a59 100%);; 
 
    overflow: hidden; 
 
    top: -50px; 
 
    left: 20%; 
 
    transform: skewX(-20deg); 
 
    z-index: -1 
 
} 
 

 
.d1:before { 
 
    content: ''; 
 
    border-radius: 30%; 
 
    position: absolute; 
 
    display: block; 
 
    width: 600px; 
 
    height: 70px; 
 
    z-index: 9999; 
 
    top: -100px; 
 
    left: -70px; 
 
    box-shadow: -50px 60px 90px 0px #000; 
 
    transform: rotate(-5deg) 
 
}
<div class="cont"> 
 
    <div class="d0"></div> 
 
    <div class="d1"> 
 
    </div> 
 
</div>

関連する問題