激情久久久_欧美视频区_成人av免费_不卡视频一二三区_欧美精品在欧美一区二区少妇_欧美一区二区三区的

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - 編程技術 - CSS3實戰匯總提高在工作中的效率(附源碼)

CSS3實戰匯總提高在工作中的效率(附源碼)

2021-12-31 23:25趣談前端徐小夕 編程技術

寫這篇文章的目的一方面是對自己工作中一些css高級技巧的總結,另一方面也是希望能教大家一些實用的技巧和高效開發css的方式,以提高在工作中的效率。

CSS3實戰匯總提高在工作中的效率(附源碼)

本文是繼筆者之前文章用css3實現驚艷面試官的背景即背景動畫(高級附源碼)的續篇也是本人最后一篇介紹css3技巧的文章,因為css這塊知識難點不是很多,更多的在于去熟悉css3的新特性和基礎理論知識。

所以寫這篇文章的目的一方面是對自己工作中一些css高級技巧的總結,另一方面也是希望能教大家一些實用的技巧和高效開發css的方式,以提高在工作中的效率。

我們將學到

  • box-shadow的高級應用
  • 制作自適應的橢圓
  • 純css3實現餅圖進度動畫
  • 用border來實現一個對話框樣式
  • css3 filter的簡單應用
  • css3偽元素實現自定義復選框
  • 在線制作css3動畫的利器

正文

1.box-shadow 的高級應用

利用css3的新特性可以幫助我們實現各種意想不到的特效,接下來的幾個案例我們來使用css3的box-shdow來實現,馬上開始吧!

實現水波動畫

知識點:box-shadow

想想我們如果不用css3,是怎么實現水波擴散的動畫呢?想必一定是寫一大堆的js才能實現如下的效果:

CSS3實戰匯總提高在工作中的效率(附源碼)

css3實現核心代碼

  1. <style> 
  2. .wave { 
  3.   margin-left: auto; 
  4.   margin-right: auto; 
  5.   width: 100px; 
  6.   height: 100px; 
  7.   border-radius: 100px; 
  8.   border: 2px solid #fff; 
  9.   text-align: center; 
  10.   line-height: 100px; 
  11.   color: #fff; 
  12.   background: #06c url(http://p3g4ahmhh.bkt.clouddn.com/me.jpg) no-repeat center center; 
  13.   background-size: 100%; 
  14.   animation: wave 4s linear infinite; 
  15. @keyframes wave { 
  16.     0% { 
  17.         box-shadow: 0 0 0 0 rgba(245, 226, 226, 1), 0 0 0 0 rgba(250, 189, 189, 1); 
  18.     } 
  19.     50% { 
  20.         box-shadow: 0 0 0 20px rgba(245, 226, 226, .5), 0 0 0 0 rgba(250, 189, 189, 1); 
  21.     } 
  22.     100% { 
  23.         box-shadow: 0 0 0 40px rgba(245, 226, 226, 0), 0 0 0 20px rgba(245, 226, 226, 0); 
  24.     } 
  25. </style> 
  26. <div class="wave"></div> 

這里我們主要使用了box-shadow的多級陰影來實現的,動畫部分我們使用的@keyframes,是不是感覺還行?

實現加載動畫

知識點:box-shadow多陰影

加載動畫大家想必也不陌生,雖然可以用很多方式實現加載動畫,比如用偽元素,用gif,用js,但是更優雅的實現我覺得還是直接上css:

CSS3實戰匯總提高在工作中的效率(附源碼)

核心代碼如下:

  1. <style> 
  2. .loading { 
  3.   margin-left: auto; 
  4.   margin-right: auto; 
  5.   width: 30px; 
  6.   height: 30px; 
  7.   border-radius: 30px; 
  8.   background-color: transparent; 
  9.   animation: load 3s linear infinite; 
  10. @keyframes load { 
  11.     0% { 
  12.         box-shadow: -40px 0 0 rgba(250, 189, 189, 0), 
  13.                     inset 0 0 0 15px rgba(250, 189, 189, 0), 
  14.                     40px 0 0 rgba(250, 189, 189, 0); 
  15.     } 
  16.     30% { 
  17.         box-shadow: -40px 0 0 rgba(250, 189, 189, 1), 
  18.                     inset 0 0 0 15px rgba(250, 189, 189, 0), 
  19.                     40px 0 0 rgba(250, 189, 189, 0); 
  20.     } 
  21.     60% { 
  22.         box-shadow: -40px 0 0 rgba(250, 189, 189, 0), 
  23.                     inset 0 0 0 15px rgba(250, 189, 189, 1), 
  24.                     40px 0 0 rgba(250, 189, 189, 0); 
  25.     } 
  26.     100% { 
  27.         box-shadow: -40px 0 0 rgba(250, 189, 189, 0), 
  28.                     inset 0 0 0 15px rgba(250, 189, 189, 0), 
  29.                     40px 0 0 rgba(250, 189, 189, 1); 
  30.     } 
  31. </style> 
  32. <div class="loading"></div> 

我們這里也是采用box-shadow多背景來實現,也是我當時思考的一個方向,至于其他的css方案,歡迎大家和我交流。

實現對話框及對話框的不規則投影

知識點:filter和偽元素

這里涉及到css濾鏡的知識,不過也很簡單,大家在css3官網上看看就理解了,我們直接看效果:

CSS3實戰匯總提高在工作中的效率(附源碼)

我們會通過filter的drop-shadow來實現不規則圖形的陰影,然后利用偽元素和border來實現頭部三角形:

  1. <style> 
  2. .odd-shadow{ 
  3.     margin-left: auto; 
  4.     margin-right: auto; 
  5.     width: 200px; 
  6.     height: 80px; 
  7.     border-radius: 8px; 
  8.     color: #fff; 
  9.     font-size: 24px; 
  10.     text-align: center; 
  11.     line-height: 80px; 
  12.     background: #06c; 
  13.     filter: drop-shadow(2px 2px 2px rgba(0,0,0,.8)) 
  14. .odd-shadow::before{ 
  15.     content: ''
  16.     position: absolute
  17.     display: block; 
  18.     margin-left: -20px; 
  19.     transform: translateY(20px); 
  20.     width:0; 
  21.     height: 0; 
  22.     border: 10px solid transparent; 
  23.     border-right-color: #06c; 
  24. </style> 
  25.  
  26. <div class="odd-shadow">哎呦,豬先森</div>復制代碼 

哎呦,豬先森復制代碼

模糊效果

知識點:filter

這個比較簡單,這里我直接上圖和代碼:

CSS3實戰匯總提高在工作中的效率(附源碼)

  1. filter: blur(20px) 

2.制作自適應的橢圓

border-radius的出現讓我們實現圓角效果提供了極大的便利,我們還可以通過對Border-radius特性的進一步研究來實現各種圖形效果,接下來就讓我們看看它的威力吧!

知識點:border-radius: a / b; //a,b分別為圓角的水平、垂直半徑,單位若為%,則表示相對于寬度和高度進行解析

CSS3實戰匯總提高在工作中的效率(附源碼)

核心代碼:

  1. <style> 
  2. .br-1{ 
  3.   width: 200px; 
  4.   height: 100px; 
  5.   border-radius: 50% /10%; 
  6.   background: linear-gradient(45deg,#06f,#f6c,#06c); 
  7. .br-2{ 
  8.   width: 100px; 
  9.   border-radius: 20% 50%; 
  10. .ani{ 
  11.   animation: skew 4s infinite; 
  12. .ani1{ 
  13.   animation: skew1 4s infinite 2s; 
  14. .ani2{ 
  15.   animation: skew2 4s infinite 3s; 
  16. @keyframes skew{ 
  17.   to
  18.     border-radius: 50%; 
  19.   } 
  20. @keyframes skew1{ 
  21.   to
  22.     border-radius: 20px 20px 100%; 
  23.   } 
  24. @keyframes skew2{ 
  25.   to
  26.     transform: rotate(360deg); 
  27.   } 
  28. </style> 
  29. <div class="br-1 black-theme"></div> 
  30. <div class="br-1 black-theme ani"></div> 
  31. <div class="br-1 black-theme ani1"></div> 
  32. <div class="br-1 br-2 black-theme ani2"></div> 

這里我們主要使用了背景漸變來實現華而不實的背景,用border-radius實現各種規格的橢圓圖案。

3.純css3實現餅圖進度動畫

知識點:border-radius: a b c d / e f g h; animation多動畫屬性;

效果如下:

CSS3實戰匯總提高在工作中的效率(附源碼)

核心代碼:

  1. <style> 
  2. .br-31{ 
  3.   width: 100px; 
  4.   height: 100px; 
  5.   border-radius: 50%; 
  6.   background: linear-gradient(to right,#f6c 50%,#333 0); 
  7. .br-31::before{ 
  8.   content: ''
  9.   display: block; 
  10.   margin-left: 50%; 
  11.   height: 100%; 
  12.   border-radius: 0 100% 100% 0 / 50%; 
  13.   background-color: #f6c; 
  14.   transform-origin: left
  15.   animation: skin 4s linear infinite, 
  16.              bg 8s step-end infinite; 
  17. @keyframes skin{ 
  18.   to
  19.     transform: rotate(.5turn); 
  20.   } 
  21. @keyframes bg{ 
  22.   50%{ 
  23.     background: #333; 
  24.   } 
  25. .br-32::before{ 
  26.   animation-play-state: paused; 
  27.   animation-delay: inherit; 
  28. </style> 
  29. <div class="br-31 black-theme"></div> 
  30. <div class="br-31 br-32 black-theme" style="animation-delay:-1s"></div>復制代碼 

這塊的實現我們主要用了漸變背景,也是實現扇形進度的關鍵,包括代碼中的如何遮擋半圓,如何對半圓做動畫,如何改變旋轉原點的位置等,這些雖然技巧性很強,但是我們稍微畫一畫,也可以實現的。

4.css3偽元素實現自定義復選框

我們都知道原生的復選框控件樣式極難自定義,這對于工程師實現設計稿的難度加大了一大截。css3的出現,增加了:checked選擇器,因此我們可以利用:checked和label來實現各式各樣的表單選擇控件,接下來讓我們來看看如何實現吧!

CSS3實戰匯總提高在工作中的效率(附源碼)

我們來看看如何實現上述自定義的復選框:

  1. <style> 
  2. .check-wrap{ 
  3.     text-align: center; 
  4. .checkbox{ 
  5.     position: absolute
  6.     clip: rect(0,0,0,0); 
  7. .checkbox[type="checkbox"]:focus + label::before{ 
  8.     box-shadow: 0 0 .6em #06c; 
  9. .checkbox[type="checkbox"] + label::before{ 
  10.     content: '\a0'; /* 不換行空格 */ 
  11.     display: inline-block; 
  12.     margin-right: .3em; 
  13.     width: 2em; 
  14.     height: 2em; 
  15.     border-radius: .3em; 
  16.     vertical-align: middle; 
  17.     line-height: 2em; /* 關鍵 */ 
  18.     font-size: 20px; 
  19.     text-align: center; 
  20.     color: #fff; 
  21.     background: gray; 
  22. .checkbox[type="checkbox"]:checked + label::before{ 
  23.     content: '\2713'; /* 對勾 */ 
  24.     background: black; 
  25.  
  26. label{ 
  27.     margin-right: 40px; 
  28.     font-size: 20px; 
  29. </style> 
  30. <div class="check-wrap"
  31.     <input type="checkbox" class="checkbox" id="check-1" /> 
  32.     <label for="check-1">生男孩</label> 
  33.     <input type="checkbox" class="checkbox" id="check-2" /> 
  34.     <label for="check-2">生女孩</label> 
  35. </div> 

生男孩 生女孩

這里為了隱藏原生的checkbox控件,我們用了clip: rect(0,0,0,0)進行截取,然后使用checkbox的偽類:checked來實現交互。

接下來擴展一下,我們來實現自定義開關:

CSS3實戰匯總提高在工作中的效率(附源碼)

這里原理是一樣的,只不過樣式做了改動,直接上代碼:

  1. <style> 
  2. .check-wrap{ 
  3.     margin-bottom: 20px; 
  4.     text-align: center; 
  5. .switch{ 
  6.     position: absolute
  7.     clip: rect(0,0,0,0); 
  8.  
  9. .switch[type="checkbox"] + label{ 
  10.     width: 6em; 
  11.     height: 3em; 
  12.     padding: .3em; 
  13.     border-radius: .3em; 
  14.     border: 1px solid rgba(0,0,0,.2); 
  15.     vertical-align: middle; 
  16.     line-height: 2em; /* 關鍵 */ 
  17.     font-size: 20px; 
  18.     text-align: center; 
  19.     color: #fff; 
  20.     box-shadow: 0 1px white inset; 
  21.     background-color: #ccc; 
  22.     background-image: linear-gradient(#ddd,#bbb); 
  23. .switch[type="checkbox"]:checked + label{ 
  24.     box-shadow: 0.05em .1em .2em rgba(0,0,0,.6) inset; 
  25.     border-color: rgba(0,0,0,.3); 
  26.     background: #bbb; 
  27.  
  28. label{ 
  29.     margin-right: 40px; 
  30.     font-size: 14px; 
  31.  
  32. .switch-an{ 
  33.     position: absolute
  34.     clip: rect(0,0,0,0); 
  35.  
  36. .switch-an[type="checkbox"] + label{ 
  37.     position: relative
  38.     display: inline-block; 
  39.     width: 5em; 
  40.     height: 2em; 
  41.     border-radius: 1em; 
  42.     color: #fff; 
  43.     background: #06c; 
  44.     text-align: left
  45.  
  46. .switch-an[type="checkbox"] + label::before{ 
  47.     content: ''
  48.     width:2em; 
  49.     height: 2em; 
  50.     position: absolute
  51.     left: 0; 
  52.     border-radius: 100%; 
  53.     vertical-align: middle; 
  54.     background-color: #fff; 
  55.     transition: left .3s; 
  56. .switch-an[type="checkbox"] + label::after
  57.     content: 'OFF'
  58.     margin-left: 2.6em; 
  59. .switch-an[type="checkbox"]:checked + label::before{ 
  60.     transition: left .3s; 
  61.     left: 3em; 
  62. .switch-an[type="checkbox"]:checked + label::after
  63.    content: 'NO'
  64.    margin-left: .6em; 
  65. </style> 
  66. <div class="check-wrap"
  67.     <input type="checkbox" class="switch" id="switch-1" /> 
  68.     <label for="switch-1">生男孩</label> 
  69.     <input type="checkbox" class="switch" id="switch-2" /> 
  70.     <label for="switch-2">生女孩</label> 
  71. </div> 
  72.  
  73. <div class="check-wrap"
  74.     <input type="checkbox" class="switch-an" id="switch-an-1" /> 
  75.     <label for="switch-an-1"></label> 
  76. </div> 

生男孩 生女孩

是不是感覺css3提供了更強大的動畫和自定義功能呢?其實我們可以實現更酷炫更實用的效果,等待你去嘗試。

5.在線制作css3動畫的利器

最后推薦一個在線制作各種貝塞爾曲線的工具,也是本人在做動畫時經常使用的:

cubic-bezier。

地址:https://cubic-bezier.com/#.17,.67,.83,.67

本文轉載自微信公眾號「趣談前端」

CSS3實戰匯總提高在工作中的效率(附源碼)

原文鏈接:https://mp.weixin.qq.com/s/VQwfNhgI9OROXgulR6Uwlg

延伸 · 閱讀

精彩推薦
Weibo Article 1 Weibo Article 2 Weibo Article 3 Weibo Article 4 Weibo Article 5 Weibo Article 6 Weibo Article 7 Weibo Article 8 Weibo Article 9 Weibo Article 10 Weibo Article 11 Weibo Article 12 Weibo Article 13 Weibo Article 14 Weibo Article 15 Weibo Article 16 Weibo Article 17 Weibo Article 18 Weibo Article 19 Weibo Article 20 Weibo Article 21 Weibo Article 22 Weibo Article 23 Weibo Article 24 Weibo Article 25
主站蜘蛛池模板: 成年男女免费视频 | 久久精品亚洲成在人线av网址 | 一区国产视频 | 国产妇女乱码一区二区三区 | www视频免费在线观看 | 国产亚洲精品综合一区 | 国产精品成人一区二区三区电影毛片 | 欧美一区二区三区免费观看 | 国产精品一区二区三区在线播放 | 久久精品在这里 | 成品片a免人视频 | 狠狠撸电影 | 91久久久久久亚洲精品禁果 | 人禽l交免费视频 | 神马久久蜜桃 | 天天骑夜夜操 | 永久免费毛片 | 国产日产精品一区二区三区四区 | 国产乱淫a∨片免费观看 | 亚洲成人国产综合 | 国产精品视频自拍 | 免费黄色日韩电影 | 亚洲无马在线观看 | 国产在线精品一区二区三区 | 国产精品久久久久久婷婷天堂 | av在线免费网 | 最新黄色电影网站 | 国产亚洲黑人性受xxxx精品 | 成人免费毛片在线观看 | 原来神马影院手机版免费 | 久久久激情网 | 日本不卡一区二区三区在线 | 精品国产一区二区三区四区在线 | 天堂成人一区二区三区 | www.射| 国产91porn| 成人在线免费看 | 欧美在线观看视频一区二区 | chinese hd xxxx tube| 久久综合福利 | 国产精品av久久久久久网址 |