CSS中的視覺效果

1.單側(cè)投影

重點:box-shadow的第四個長度參數(shù),擴(kuò)張半徑。

單側(cè)投影:
box-shadow: 0 5px 4px -4px black;//將擴(kuò)張半徑,設(shè)為高斯模糊的負(fù)值
Paste_Image.png
鄰邊投影:
box-shadow:3px 3px 6px -3px black;//將將擴(kuò)張半徑,設(shè)為高斯模糊的負(fù)值的一半;將位移值設(shè)為高斯模糊的一半。
Paste_Image.png
雙側(cè)投影:
box-shadow:5px 0px 5px -5px black, -5px 0px 5px -5px black;
//將單側(cè)投影技巧應(yīng)用兩次。
Paste_Image.png

2.不規(guī)則投影

問題:單用box-shadow不能對不規(guī)則的形狀,例如:透明、折角效果、對話氣泡等。

解決方案:應(yīng)用濾鏡效果規(guī)范

幾個濾鏡串起來

filter: blur() grayscale() drop-shadow();

box-shadow: 2px 2px 10px rgba(0,0,0,.5);

改成

filter: drop-shadow(2px 2px 10px rgba(0,0,0,.5));
Paste_Image.png

重點代碼:

               /*box-shadow: .1em .1em .3em rgba(0,0,0,.5);*/

               -webkit-filter:drop-shadow(.1em .1em .1emrgba(0,0,0,.5));

               filter:drop-shadow(.1em .1em .1emrgba(0,0,0,.5));

<div class="speech">Speech bubble</div>

<div class="dotted">Dotted border</div>

<div class="cutout">Cutout corners</div>

 

 

div {

               position:relative;

               display:inline-flex;

               flex-direction:column;

               justify-content:center;

               vertical-align:bottom;

               box-sizing:border-box;

               width:5.9em;

               height:5.2em;

               margin:.6em;

               background:#fb3;

               /*box-shadow: .1em .1em .3em rgba(0,0,0,.5);*/

               -webkit-filter:drop-shadow(.1em .1em .1emrgba(0,0,0,.5));

               filter:drop-shadow(.1em .1em .1emrgba(0,0,0,.5));

               font:200%/1.6Baskerville, Palatino, serif;

               text-align:center;

}

 

.speech {

               border-radius:.3em;

}

 

.speech::before {

               content:'';

               position:absolute;

               top:1em;

               right:-.7em;

               width:0;

               height:0;

               border:1em solidtransparent;

               border-left-color:#fb3;

               border-right-width:0;

}

 

.dotted {

               background:transparent;

               border:.3em dotted#fb3;

}

 

.cutout {

               border:.5em solid#58a;

               border-image:1url('data:image/svg+xml,\

                                    <svg xmlns="http://www.w3.org/2000/svg"\

                                                width="3" height="3" fill="%23fb3">\

                                                  <polygon points="0,1 1,0 2,0 3,1 3,2 2,3 1,3 0,2"/>\

                                         </svg>');

               background-clip:padding-box;

}

3.染色效果

基于濾鏡的方案

sepia() 降低飽和度的橙黃色效果

saturate() 提高每個像素的飽和度

hue-rotate() 每個像素的色相以指定的度數(shù)進(jìn)行偏移

img {

               max-width:640px;

               transition:1s filter,1s -webkit-filter;

               filter:sepia()saturate(4) hue-rotate(295deg);

}

 

img:hover,

img:focus {

               filter:none;

}

Paste_Image.png
基于混合模式的方案

混合模式:luminosity,保留上層元素的HSL亮度信息,并從下層吸取色相飽和度。所以把下層設(shè)置成我們想要的色相飽和度,再混合可以保證圖片亮度。

方案:第一種,把圖片放在一個容器中,容器背景設(shè)成我們要的色調(diào);第二種:不要圖片元素,用<div>元素,第一層背景為圖片,第二次背景為主色調(diào)。

<img>方法

<a href="#">

![](http://upload-images.jianshu.io/upload_images/4648896-b3485a5b716ebd66.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

</a>

 

a{

    display:inline-block;

    background:hsl(335, 100%, 50%);

}

 

a img {

               mix-blend-mode:luminosity;

               max-width:640px;

}

 
Paste_Image.png

4.毛玻璃效果

解決方案:應(yīng)用偽元素,將其置于元素下層,偏移量設(shè)置為0,進(jìn)行blur()模糊處理。

注意:模糊效果的邊緣會逐漸減弱,因此,要讓偽元素相對宿主元素的尺寸再向外擴(kuò)張至少-20px,保險起見,取-30px。對于超出尺寸部分,對main元素設(shè)置,overflow:hidden,來解決。

<main>

<blockquote>“The only way to
get rid of a temptation is to yield to it. Resist it, and your soul grows sick
with longing for the things it has forbidden to itself, with desire for what
its monstrous laws have made monstrous and unlawful.”</em>

<footer>— <cite>Oscar Wilde, The
Picture of Dorian Gray</cite></footer>

</blockquote>

</main>

body {

               min-height:100vh;

               box-sizing:border-box;

               margin:0;

               padding-top:calc(50vh - 6em);

               font:150%/1.6 Baskerville,
Palatino, serif;

}

 

body,
main::before {

               background:url("http://csssecrets.io/images/tiger.jpg")
0 / cover fixed;

}

 

main {

               position:relative;

               margin:0 auto;

               padding:1em;

               max-width:23em;

               background:hsla(0,0%,100%,.25)
border-box;

               overflow:hidden;  //消除擴(kuò)張影響

               border-radius:.3em;

               box-shadow:0 0 0 1px hsla(0,0%,100%,.3)
inset,

                           0 .5em 1em rgba(0, 0, 0, 0.6);

               text-shadow:0 1px 1px hsla(0,0%,100%,.3);

}

 

main::before {

               content:'';

               position:absolute;

               top:0;right:0;bottom:0;left:0;

               margin:-30px;  //擴(kuò)大邊界

               z-index:-1;

               -webkit-filter:blur(20px);

               filter:blur(20px); //模糊處理

}

 

blockquote {font-style:italic }

blockquote cite {font-style:normal;}

Paste_Image.png

本文整理自《CSS揭秘》,推薦閱讀

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 寫在前面的話 上一篇文章對簡單濾鏡實現(xiàn)有一定的講解,那么這一篇則是對圖像處理更加深層次的說明,對于一張圖片怎么處理...
    前世小書童閱讀 5,635評論 8 32
  • 發(fā)現(xiàn) 關(guān)注 消息 iOS 第三方庫、插件、知名博客總結(jié) 作者大灰狼的小綿羊哥哥關(guān)注 2017.06.26 09:4...
    肇東周閱讀 15,410評論 4 61
  • 對酒當(dāng)歌,人生幾何! 譬如朝露,去日苦多。 慨當(dāng)以慷,憂思難忘。 何以解憂?惟有杜康。
    墨海擒龍閱讀 314評論 0 0
  • 國慶節(jié)的前一天,忽然想起,校園里的桂花開了沒有,深呼吸,并沒有聞到桂花的味道。往年,不用走到...
    靜文思語楊秀明閱讀 484評論 0 5
  • 紅房子的奶油小方媽媽說有一種魔力能讓孩子時的我破涕為笑再不開心的事都能忘記 長大的我不再容易哭泣長大的世界讓笑戴上...
    天書閱讀 352評論 0 1

友情鏈接更多精彩內(nèi)容