16-不规则投影
<div class="speech">Speech bubble</div> <div class="dotted">Dotted border</div> <div class="cutout">Cutout corners</div> /** * Irregular drop-shadows */ 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 .1em rgba(0,0,0,.5)); filter: drop-shadow(.1em .1em .1em rgba(0,0,0,.5)); font: 200%/1.6 Baskerville, Palatino, serif; text-align: center; } .speech { border-radius: .3em; } .speech::before { content: ''; position: absolute; top: 1em; right: -.7em; width: 0; height: 0; border: 1em solid transparent; border-left-color: #fb3; border-right-width: 0; } .dotted { background: transparent; border: .3em dotted #fb3; } .cutout { border: .5em solid #58a; border-image: 1 url('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; }
17-染色效果
基于滤镜的方案
/** * Color tinting — with filters */ img { max-width: 640px; transition: 1s filter, 1s -webkit-filter; -webkit-filter: sepia() saturate(4) hue-rotate(295deg); filter: sepia() saturate(4) hue-rotate(295deg); } img:hover, img:focus { -webkit-filter: none; filter: none; }
基于混合模式的方案
/** * Color tinting — with blending modes */ .tinted-image { width: 300px; height: 440px; background-size: cover; background-color: hsl(335, 100%, 50%); background-blend-mode: luminosity; transition: .5s background-color; } .tinted-image:hover { background-color: transparent; }
18-毛玻璃效果
背景知识:PGBA/HSLA 颜色
, filter: blur()
/** * Frosted glass effect */ 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://placekitten.com/200/300") 0 / cover fixed; } main { position: relative; margin: 0 auto; padding: 1em; max-width: 23em; background: hsla(0,0%,100%,.25) border-box; overflow: hidden; 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; z-index: -1; -webkit-filter: blur(20px); filter: blur(20px); } blockquote { font-style: italic } blockquote cite { font-style: normal; }
19-折角效果
背景知识: css 变形, css 渐变, “切角效果”
45度折角的解决方案
/** * Folded corner effect */ div { width: 12em; background: #58a; /* Fallback */ background: linear-gradient(to left bottom, transparent 50%, rgba(0,0,0,.4) 0) 100% 0 no-repeat, linear-gradient(-135deg, transparent 1.5em, #58a 0); background-size: 2em 2em, auto; padding: 2em; color: white; font: 100%/1.6 Baskerville, Palatino, serif; }
其他角度的解决方案
/** * Folded corner effect — at an angle */ div { position: relative; width: 12em; background: #58a; /* Fallback */ background: linear-gradient(-150deg, transparent 1.5em, #58a 0); padding: 2em; color: white; font: 100%/1.6 Baskerville, Palatino, serif; border-radius: .5em; } div::before { content: ''; position: absolute; top: 0; right: 0; width: 1.73em; height: 3em; background: linear-gradient(to left bottom, transparent 50%, rgba(0,0,0,.2) 0, rgba(0,0,0,.4)) 100% 0 no-repeat; transform: translateY(-1.3em) rotate(-30deg); transform-origin: bottom right; border-bottom-left-radius: .5em; box-shadow: -.2em .2em .3em -.1em rgba(0,0,0,.15) }
总结
本文整理了《css揭秘中》19个有趣的css 技巧案例,下篇将继续整理剩下的 28 个。