国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > CSS > 正文

CSS實現鏤空效果的示例代碼

2024-07-11 08:59:44
字體:
來源:轉載
供稿:網友

效果原理

主要利用css漸變實現一些不需要切圖的背景鏤空

優惠券樣式

.mixinsTicket(@width, @height, @r, @left, @lcolor, @rcolor) {    width: @width;    height: @height;    background:              radial-gradient(circle at top right, transparent @r, @lcolor 0) -(@width - @left) top ~'/' 100% 51% no-repeat,              radial-gradient(circle at bottom right, transparent @r, @lcolor 0) -(@width - @left) bottom ~'/' 100% 51% no-repeat,              radial-gradient(circle at top left, transparent @r, @rcolor 0) @left 0 ~'/' 100% 51% no-repeat,              radial-gradient(circle at bottom left, transparent @r, @rcolor 0) @left bottom ~'/' 100% 51%  no-repeat;}

.mixinsTicket1(@width, @height, @r, @top, @color) {   width: @width;   height: @height;   background:               radial-gradient(circle at bottom left, transparent @r, @color 0) left (@top - @height) ~'/' 51% 100% no-repeat,               radial-gradient(circle at top left, transparent @r, @color 0) left @top ~'/' 51% 100% no-repeat,               radial-gradient(circle at bottom right, transparent @r, @color 0) right (@top - @height) ~'/' 51% 100% no-repeat,               radial-gradient(circle at top right, transparent @r, @color 0) right @top ~'/' 51% 100%  no-repeat;   &::after{     content: '';     display: block;     position: absolute;     width: calc(100% - 2 * @r);     left: @r;     top: @top;     border-top: 1px dashed #fff;     transform: translateY(.5);   }}

切角效果

ps: 鋸齒跟設備的顯示有關系

.mixinFlag(@width, @height, @bg) when(default()) {    width: @width;    height: @height;    background:              linear-gradient(45deg, transparent sqrt(pow(@width/2, 2)/2), @bg 0) right,              linear-gradient(-45deg, transparent sqrt(pow(@width/2, 2)/2),  @bg 0) left;    background-size: 50% 100%;    background-repeat: no-repeat; } .mixinFlag(@width, @height, @bg) when(@width > @height) {    width: @width;    height: @height;    background:              linear-gradient(-45deg, transparent sqrt(pow(@height/2, 2)/2), @bg 0) top left,              linear-gradient(-135deg, transparent sqrt(pow(@height/2, 2)/2), @bg 0) bottom left;    background-size: 100% 50%;    background-repeat: no-repeat;}

.mixinsMark(@width, @height, @bg) {    width: @width;    height: @height;    background:              linear-gradient(-45deg, transparent sqrt(pow(@height/2, 2)/2), @bg 0) bottom left,              linear-gradient(-135deg, transparent sqrt(pow(@height/2, 2)/2), @bg 0) top left;    background-size: 100% 50%;    background-repeat: no-repeat;}

ps:以上效果四個方向都可以實現,其他方向代碼沒有貼出,原理相同

格子布

css {    width: 510px;    height: 128px;    background: #FFF;    background-image: linear-gradient(rgba(182, 128, 102, .8) 8px, transparent 0),                      linear-gradient(90deg, rgba(182, 128, 102, .8) 8px, transparent 0);    background-size: 8px 14px, 14px 8px;}

焦點

.mask {  position: fixed;  top: 0;  left: 0;  z-index: 100;  width: 100vw;  height: 100vh;  background:  radial-gradient(closest-side at 50% 278rpx, transparent 140rpx, rgba(0, 0, 0, .12) 180rpx, rgba(0, 0, 0, .22) 200rpx, rgba(0,0,0,.3) 220rpx, rgba(0,0,0, .4)) no-repeat;}

總結

每一層漸變都可被當做一張背景圖,也就是說每一層漸變都可以指定其position、size、repeat。玩過PS的的同學應該知道圖層的概念,咱們的背景圖層疊原理也類似(當然,漸變也可以當背景圖),控制漸變的大小,哪里需要鏤空,以及需要顯示的位置、是否平鋪,就可以實現大多數場景下的基本效果,當然,一張切圖來的更快,但是有時候切圖并不能適應所有的場景。

掌握background的書寫順序可以幫助在腦海中構思自己想要的效果:


復制代碼
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 新民市| 类乌齐县| 张家口市| 饶河县| 奉化市| 平邑县| 吉木萨尔县| 阜城县| 万宁市| 上高县| 玉山县| 陆川县| 沅陵县| 礼泉县| 昌图县| 河南省| 淮南市| 平顺县| 额尔古纳市| 喜德县| 施秉县| 韩城市| 东安县| 崇左市| 汕尾市| 西乡县| 廊坊市| 宣城市| 册亨县| 偏关县| 锡林浩特市| 厦门市| 永福县| 东平县| 宝清县| 潢川县| 太仓市| 阆中市| 大石桥市| 遂平县| 镇原县|