咱們每次畫一個圖片,肯定先要確定一個容器,確定一下圖形的位置和大小 ...
貓咪容器
- 咱們每次畫一個圖片,肯定先要確定一個容器,幾確定一下圖形的位置和大小。
<div class="mao_box"> <div class="mao"></div> </div> body {margin: 0px;background: #F6F7A7;} .mao_box {position: relative;top: 50px ;} /*設置寬度並且居中顯示*/ .mao {margin: 0 auto;width: 400px;}
畫喵咪的頭部和頭部的花紋
- 按照繪畫習慣,我們肯定是先畫最大的頭部,頭部確定了,耳朵嘴巴的位置才能確定。
<!-- 貓咪的頭部框架 --> <div class="mao_head"> <div class="huawen"> <div><!--頭部花紋——左邊橙色--></div> </div> </div> .mao_head { width: 400px; /*設置高度和寬度*/ height: 340px; background: #F6F7F2; position: relative; border-radius: 50% 50% 35% 35%; /*畫出貓臉的形狀*/ border: solid 2px #2e2e2e; /*給貓咪畫一個偏黑色的邊框*/ overflow: hidden; z-index: 10; } .huawen { position: absolute; height: 160px; /*設置寬度和高度*/ width: 180px; background: #8D8D8D; left: 110px; /*距離貓臉左面110px的位置,正好在中間位置 (400-180)/2*/ border-radius: 0% 0% 50% 50%; /*畫出花紋的形狀,下麵為圓角邊框*/ overflow: hidden; /*花紋超出頭部的部分隱藏*/ } .huawen > div:first-child { /*花紋的左右兩邊顏色不一樣,所以改變左邊半邊的顏色為橙色*/ height: 160px; width: 90px; /*寬度和花紋總寬度的一半*/ background: #F0AC6B; }
貓咪頭部.png
畫貓咪的耳朵部分
- 貓咪的耳朵分佈在頭部的左右兩邊,所以肯定是由兩個div畫成,為了不顯得那麼僵硬,我們可以把兩邊的耳朵稍微畫的不一樣大。
- 大家肯定會想:耳朵的形狀這麼奇怪,到時是怎麼畫的呢?其實很簡單,就是通過矩形然後設置各個角度的border-radius就會形成一種尖角的效果,再旋轉相應的角度跟頭部貼合就可以了。
- 最後將耳朵隱藏在臉部的後面,露出一點點耳尖就可以了。
<!--繪製耳朵的容器--> <div class="erduo"> <div></div><!--繪製左耳--> <div></div><!--繪製右耳--> </div> /*耳朵*/ .erduo { width: 374px; /*設置耳朵容器的高度和寬度*/ height: 120px; position: absolute; top: -6px; /*將耳朵的位置放到對應的地方*/ left: 50%; margin-left: -187px; } /*左耳*/ .erduo > div:first-child { height: 200px; /*設置左耳的高度和寬度*/ width: 160px; border: 2px solid #2e2e2e; /*給左耳設置一個邊框*/ background: #f3f3f3; border-radius: 4% 80% 0% 50%; /*設置左耳各個角度的圓角程度*/ transform: rotate(-15deg); /*設置左耳的旋轉角度*/ -ms-transform: rotate(-15deg); -moz-transform: rotate(-15deg); -webkit-transform: rotate(-15deg); -o-transform: rotate(-15deg); position: absolute; left: -20px; top: 0px; transition: transform 1s,left 1s; /*設置左耳的hover動效*/ } /*右耳跟左耳的畫法同理*/ .erduo > div:last-child { height: 180px; width: 160px; border: 2px solid #2e2e2e; background: #f3f3f3; transform: rotate(15deg); -ms-transform: rotate(15deg); -moz-transform: rotate(15deg); -webkit-transform: rotate(15deg); -o-transform: rotate(15deg); border-radius: 80% 4% 50% 0%; position: absolute; right: -20px; top: 0px; transition: transform 1s,right 1s; }
耳朵.jpg
畫貓咪的眼睛部分
-
眼睛部分有點複雜喲,不經過仔細的一番研究和強大的想象力是很難畫出來的:解剖一下就是上下兩個橢圓重疊而成,多餘的部分隱藏,中間的褐色眼珠是在上面圓形中的一個黑色矩形。
<div class="yanjing"> <div> <div class="yanquan"> <div></div> <!--存放豎著的眼球的div--> </div> <div class="yanquan_hedding"> <!--存放眼睛下睫毛的div--> </div> <div class="hong"></div> </div> <div class="yan_right"> <div class="yanquan"> <div></div> </div> <div class="yanquan_hedding"> </div> <div class="hong"></div> </div> <div style="clear:both"></div> </div> /*眼睛*/ .yanjing { height: 60px; /*設置眼睛整體的高度和寬度,多餘的部分隱藏*/ width: 300px; position: absolute; /*設置眼睛的位置,使它定位在臉部中間*/ top: 200px; z-index: 20; left: 50%; margin-left: -150px; overflow: hidden; } /*左眼*/ .yanquan { height: 100px; /*設置左眼的高度和寬度,多餘的部分隱藏*/ width: 100px; border: 2px solid #2e2e2e; border-radius: 50% 50% 50% 50%; overflow: hidden; position: absolute; } /*黑色眼珠子 左*/ .yanquan > div { height: 100px; width: 30px; background-color: #2e2e2e; margin-left: 35px; /*將黑色眼珠子定義在眼睛的中間*/ transition:all 1s; } /*眼睛下睫毛部分*/ .yanquan_hedding { height: 100px; width: 180px; border-top: 2px solid #2e2e2e; border-radius: 50% 50% 50% 50%; background: #F6F7F2; /*背景色臉部的背景色一樣,這樣就只能看見上邊框了*/ margin-top: 50px; /*定義位置與眼睛融為一體*/ margin-left: -40px; position: absolute; transition: margin-top 1s; /*為後面的hover動態做準備*/ } /*右邊眼睛的整體定義,其它都跟左眼一樣,就是位置不一樣*/ .yan_right { left: 196px; top: 0px; position: absolute; }
貓咪眼睛.jpg
畫貓咪的臉部花紋
- 喵咪的鬍鬚可是很重要的喲,如果不小心把它剪了可是很嚴重的,貓咪就再也無法測量自己可以鑽進多大的洞里了,哈哈。
- 仔細觀察花紋其實就是由左右各5條線條組成,畫出線條再做相應的變換就可以了。
<div class="face_huawen"> <!-- 存放花紋的div --> <div class="face_huawen_huawen huawen_left"> <!-- 存放每一個線條的div --> <div></div> <div></div> <div></div> <div></div> <div></div> </div> <div class="face_huawen_huawen huawen_right"> <div></div> <div></div> <div></div> <div></div> <div></div> </div> <div style="clear:both"></div> </div> /*臉部花紋*/ /*左邊花紋*/ .face_huawen { height: 80px; /*設置花紋整體的高度和寬度*/ width: 380px; position: absolute; /*設置花紋在臉部的位置*/ top: 190px; z-index: 20; left: 50%; margin-left: -190px; } .face_huawen_huawen > div:first-child { /*設置第一條花紋的寬高和變化情況(圓角大小和旋轉角度)*/ width: 30px; height: 10px; border-top: 6px #E53941 solid; border-radius: 30% 80% 20% 50%; transform: rotate(25deg); -ms-transform: rotate(25deg); -moz-transform: rotate(25deg); -webkit-transform: rotate(25deg); -o-transform: rotate(25deg); margin-left: 20px; } .face_huawen_huawen > div:nth-child(2) { /*設置第二條花紋*/ width: 20px; height: 6px; background-color: #E53941; border-radius: 50% 50% 50% 50%; transform: rotate(25deg); -ms-transform: rotate(25deg); -moz-transform: rotate(25deg); -webkit-transform: rotate(25deg); -o-transform: rotate(25deg); margin-left: 20px; } .face_huawen_huawen > div:nth-child(3) {/*設置第三條花紋*/ /*margin-top:10px;*/ width: 32px; height: 10px; border-bottom: 4px #E53941 solid; border-radius: 30% 0% 90% 30%; transform: rotate(25deg); -ms-transform: rotate(25deg); -moz-transform: rotate(25deg); -webkit-transform: rotate(25deg); -o-transform: rotate(25deg); margin-left: 8px; } .face_huawen_huawen > div:nth-child(4) {/*設置第四條花紋*/ margin-top: 20px; width: 26px; height: 20px; border-bottom: 4px #E53941 solid; border-radius: 30% 0% 90% 30%; transform: rotate(30deg); -ms-transform: rotate(30deg); -moz-transform: rotate(30deg); -webkit-transform: rotate(30deg); -o-transform: rotate(30deg); margin-left: 28px; } .face_huawen_huawen > div:last-child {/*設置第二五條花紋*/ width: 22px; height: 10px; border-bottom: 3px #E53941 solid; border-radius: 0% 0% 50% 50%; transform: rotate(-15deg); -ms-transform: rotate(-15deg); -moz-transform: rotate(-15deg); -webkit-transform: rotate(-15deg); -o-transform: rotate(-15deg); margin-left: 40px; margin-top: -8px; } /*右邊花紋,右邊花紋的位置和旋轉角度跟左邊花紋不一樣,其它變換都一樣*/ .huawen_right { float: right; transform: rotateY(180deg); -webkit-transform: rotateY(180deg); /* Safari 和 Chrome */ -moz-transform: rotateY(180deg); /* Firefox */ margin-top: -85px; }
貓咪臉部花紋.jpg
畫貓咪的鼻子
- 感覺這是整個貓咪最好畫的地方了,簡單的一個半圓就可以解決問題啦~啦啦啦啦~
<div class="bizi"> <div></div> </div> /*鼻子,不多做解釋了,方法都差不多:確定位置和形狀即可*/ .bizi { width: 30px; height: 36px; position: absolute; left: 50%; margin-left: -15px; top: 260px; z-index: 30; } .bizi > div { width: 30px; height: 10px; border-bottom: 8px solid #2e2e2e; border-radius: 0% 0% 50% 50%; margin-top: -10px; }
貓咪的鼻子.png
畫貓咪的嘴巴
- 咦?是不是感覺畫著畫著就到了最後一部分了,哈哈哈哈哈,好開心啊~又吃成長快樂了~
- 嘴巴就像兩撇小鬍子,用兩個矩形邊框就可以實現了。
<div class="zuiba_box"> <div class="zuiba"> <div></div> <div></div> </div> </div> .zuiba { /*設置嘴巴的位置*/ margin-left: 85px; margin-top: 6px; } /*右半邊嘴巴*/ .zuiba > div:first-child { width: 50px; height: 40px; border-bottom: 4px solid #2e2e2e; /*設置底部和左邊邊框,形成直角矩形*/ border-left: 4px solid #2e2e2e; border-radius:40% 0% 20% 50%; /*設置各邊的圓角程度*/ margin-left: 13px; margin-top: -26px; position:absolute; transition: border-radius 1s; /*為動效做過渡效果*/ } /*左半邊嘴巴*/ .zuiba > div:nth-child(2) { width: 50px; height: 40px; border-bottom: 4px solid #2e2e2e; border-right: 4px solid #2e2e2e; border-radius:0% 40% 50% 20%; margin-left: -38px; margin-top: -26px; position:absolute; transition: border-radius 1s; }
貓咪嘴巴.jpg
各個部位拼接成一個完整的小貓
- 各個部位都畫好之後,又到了像大白一樣的拼圖時間了,哈哈~大家一起拼出一個萌萌噠小貓吧~(主要是對transition屬性的運用,設置:hover之後的屬性,然後用transition設置屬性完成變化的過渡時間)
拼圖咯--哈哈.jpg
製作滑鼠移動上去的動態效果
- 我們家毛球可是個動如脫兔的家伙哦,所以我們來給貓咪加點特效吧~(^__^)
- 滑鼠移動上去之後兩耳耳朵左右擺動
- 眼睛眯眯呈現笑臉的形狀
- 嘴角上揚
/*滑鼠浮動耳朵樣式*/ .mao:hover .erduo > div:first-child { left: -10px; transform: rotate(0deg); -ms-transform: rotate(0deg); -moz-transform: rotate(0deg); -webkit-transform: rotate(0deg); -o-transform: rotate(0deg); border-radius: 4% 80% 0% 60%; } .mao:hover .erduo > div:last-child { right: -10px; transform: rotate(0deg); -ms-transform: rotate(0deg); -moz-transform: rotate(0deg); -webkit-transform: rotate(0deg); -o-transform: rotate(0deg); border-radius: 80% 4% 60% 0%; /*transition: transform 1s,right 1s;*/ } /*眯眼並且出現紅暈的動態效果,眼珠的寬度變寬*/ .mao:hover .yanquan > div:first-child { width:40px; margin-left: 30px; } .hong { position: absolute; height: 28px; width: 70px; background: red; top: 34px; /*top: 64px;*/ left: 18px; border-radius: 50% 50% 50% 50%; background-image: -moz-radial-gradient( 50% 50%, rgba(253,214,240,0.8) 0%, rgba(253,224,244,0.8) 66%, rgba(253,234,247,0.8) 100%); background-image: -webkit-radial-gradient( 50% 50%, rgba(253,214,240,0.8) 0%, rgba(253,224,244,0.8) 66%, rgba(253,234,247,0.8) 100%); background-image: -ms-radial-gradient( 50% 50%, rgba(253,214,240,0.8) 0%, rgba(253,224,244,0.8) 66%, rgba(253,234,247,0.8) 100%); opacity: 0.0; /*transition: opacity 0.5s ease-in 0.2s;*/ } /*眼睛浮動屬性*/ .mao:hover .yanquan_hedding { margin-top: 30px; /*transition: margin-top 1s;*/ } .mao:hover .hong { /*top: 34px;*/ opacity: 0.8; transition: opacity 0.5s ease-in 0.2s; } /*嘴巴上揚的效果*/ .mao:hover .zuiba > div:first-child { border-radius: 50% 50% 50% 50%; width: 40px; } .mao:hover .zuiba > div:nth-child(2) { width: 40px; margin-left: -30px; border-radius: 50% 50% 50% 50%; }
PS:眼睛眯起來之後下麵出現了一部分紅暈,就是兩個背景顏色半透明的小橢圓組成的,只要在滑鼠移動上去只會把橢圓顯示出來就可以了。
眼睛下麵的紅暈.png
學習過程中遇到什麼問題或者想獲取學習資源的話,歡迎加入學習交流群
343599877,我們一起學前端!