目錄
背景與邊框第一部分
背景與邊框第二部分
形狀
視覺效果
字型排印
使用者體驗
結構與布局
過渡與動畫
源碼下載
一、單側陰影
.wrap{ width: 200px; height: 120px; background: yellowgreen; box-shadow: 2px 0px 4px -2px black, -2px 0px 4px -2px black;}
二 、不規則投影
.wrap{ width: 200px; height: 120px; border: 6px dotted yellowgreen; --box-shadow: 0px 0px 4px 0px black; -webkit-filter: drop-shadow(2px 0px 2px rgba(0,0,0,1)) }
三、染色體效果
基於濾鏡實現,應用filter屬性的相關值,調整圖片的飽合度、亮度等值
基於min-blend-mode實現,作用:實現元素內容與背景以及下面的元素髮生“混合”
基本background-blend-mode實現,作用:實現背景顏色與背景圖片、背景圖片與圖片的混合
三種情況的範例程式碼:
.wrap1{ width: 200px; height: 120px; overflow: hidden; } .wrap1 > img{ max-height: 100%; max-width: 100%; -webkit-filter: sepia(1) saturate(4) hue-rotate(150deg); } .wrap2{ width: 200px; height: 120px; background: hsl(335, 100%, 50%); overflow: hidden; } .wrap2 > img{ height: 100%; width: 100%; mix-blend-mode: luminosity; } .wrap3{ width: 200px; height: 120px; background-size: cover; background-color: hsl(335, 100%, 50%); background-image: url("../img/cat.png"); background-blend-mode: luminosity; }
四、毛半透明效果
主要實現原理:內容虛擬元素背景與底層背景相同的圖片;並加上filter:blur模糊濾鏡即可。注意blur不能應用在底層背景,也不能應用在元素的背景上(這樣會地元素本身應用blur模糊,會導致文本看不見),只能就用在虛擬元素上。
代碼如下:
body{ background: url("../img/cat.png") no-repeat; background-size: cover;}.wrap{ position: relative; width: 500px; margin: 0px auto; padding: 10px; line-height: 1.5; background: hsla(0, 0%, 100%, .3); overflow: hidden;}.wrap::before{ content: ''; background: url("../img/cat.png") 0/cover fixed; position: absolute; top: 0; right: 0; bottom: 0; left: 0; filter: blur(20px); z-index: -1; margin: -30px;}
代碼說明:
body與wrap虛擬元素都應用相同的背景圖片
wrap的background-attachment設定為fixed,讓背景圖不要跟隨滾動一起動
wrap虛擬元素設定為絕對位置,且z-index層級只高於背景
利用blur設定wrap虛擬元素的模糊尺寸
用margin負值增加寬度,父元素用overflow:hidden隱藏溢出,讓模糊背景更加真實。
五、折角效果
實現步驟
.wrap{ background: linear-gradient(to left bottom, transparent 50%, rgba(0, 0, 0, .4) 0) no-repeat 100% 0/2em 2em, linear-gradient(-135deg, transparent 1.4em, #58a 0); width: 200px; height: 120px; }
注意
100% 0/2em 2em在定位背景元素的位置與寬高,尤其是2em的寬與高都是背景元素正常的寬度。
而第二個linear-gradient中的1.4em是沿著漸層軸進行度量的,也就是漸層軸到元素頂邊的距離,本例是漸層軸到右上邊頂的距離
to left bottom是表示漸層從左下角開始