CSS3繪製騰訊QQ企鵝

開始著手於QQ 企鵝的繪製, 第一步基本框架的繪製。

CSS3繪製騰訊QQ企鵝

通過對Logo圖像的觀察,按照層次劃分來組合最終的效果。選擇使用絕對位置position:absolute;來佈局各個元素。主要劃分為頭部,身體,圍脖,雙手,雙腳。

  

基本框架結構就是這樣的,QQ 對於容器是通過絕對定位來對每個元素佈局進行設置的。

QQ Logo容器(畫板):

/** * QQ Logo 繪製 */#qq { position: relative; margin: 0 auto; width: 420px; height: 400px; outline: gold solid 2px;}

骨架出來了,那我們就開始一步步的進行繪製了,先從頭開始:

繪製 head 前,還是跟步驟1一樣,先對 head 的層次結構劃分清楚,依次為:左眼、右眼、上嘴唇、下嘴唇、嘴唇的層次感體現

 

繪製 head 的輪廓:

 /* QQ head */.head { position: absolute; top: 18px; left: 96px; width: 234px; height: 185px; border: 1px solid #000; /* 通過對border-radius 圓弧的層度來進行鉤畫 */ border-top-left-radius: 117px 117px; border-top-right-radius: 117px 117px; border-bottom-left-radius: 117px 68px; border-bottom-right-radius: 117px 68px;}
CSS3繪製騰訊QQ企鵝

圖中為什麼圓弧是設置成 border-bottom-left-radius: 117px 68px; 一般根據設計圖出來後導出轉成帶有標尺圖後,會自動計算出值;如果沒有的話,那就要通過計算了。

然後依次繪製 head 其他結構:

眼睛

/* 眼睛 */.eye { position: absolute; width: 44px; height: 66px; border:1px solid #000; border-radius: 50% 50%;}.left.eye { left: 62px; top: 50px;}.right.eye { left: 132px; top: 50px;}
CSS3繪製騰訊QQ企鵝

/* QQ head -> mouth */.mouthTopContainer { position: absolute; top: 120px;left: 39px; width: 158px; height: 29px; border: 1px solid #000;}.mouthBottomContainer { position: absolute; top: 146px;left: 39px; width: 158px; height: 15px; border: 1px solid #000;}
CSS3繪製騰訊QQ企鵝

到這裡基本頭的骨架就出來,然後就是對頭的骨架結構的線條進行修飾,現在太醜了,對吧!

眼睛

/* QQ head -> eye */.eye { position: absolute; width: 44px; height: 66px; border:1px solid #000; border-radius: 50% 50%;}.left.eye { left: 62px; top: 50px;}.right.eye { left: 132px; top: 50px;}.innerLeftEye { position: absolute; top: 20px; left: 20px; width: 18px; height: 24px; border-radius: 50%; border: 1px solid #000;}.innerLeftEye::after { content: ""; position: absolute; top: 6px; left: 9px; width: 6px; height: 8px; border: 1px solid #000; border-radius: 50%;}.innerRightEye { position: absolute; top: 20px; left: 8px; /* 月牙眼球外輪廓 */ width: 18px; height: 24px; border: 1px solid #000; border-top-left-radius: 50% 90%; border-top-right-radius: 50% 90%; border-bottom-left-radius: 50% 10%; border-bottom-right-radius: 50% 10%;}.innerRightEye::after { content: ""; position: absolute; bottom: -1px;left: 4px; /* 月牙眼球內部輪廓 */ width: 10px; height: 13px; border: 1px solid #000; border-top-left-radius: 50% 100%;border-top-right-radius: 35% 80%;}.fix { position: absolute; top: 17px; width: 4px; height: 4px; border: 1px solid #000; border-radius: 50%;}.fix:after{content: ""; position: absolute; top: 0;left: 14px;width: 4px; height: 4px; border: 1px solid #000;border-radius: 50%;}
CSS3繪製騰訊QQ企鵝

/* QQ head -> mouth */.mouthTopContainer { /* 定位 */ position: absolute; top: 120px;left: 39px; width: 158px; height: 29px; overflow: hidden; /* 隱藏超出部分 */}.mouthTop { /* 上嘴唇輪廓 */ position: absolute; top: 0;left: 0; width: 158px; height: 34px; border: 1px solid #000; border-top-left-radius: 45% 34px;border-top-right-radius: 45% 34px;}.mouthBottomContainer { position: absolute; top: 146px;left: 39px; width: 158px; height: 15px; overflow: hidden; /* 隱藏超出部分 */}.mouthBottom { position: absolute; top: -4px;left: 0; width: 158px; height: 24px; border: 1px solid #000; border-top:none; border-bottom-left-radius: 45% 24px;border-bottom-right-radius: 45% 24px;}/* 嘴唇上下層次感-咬合部位 */.lispContainer { /* 定位 */ position: absolute;top: 146px;left: 60px; width: 116px; height: 24px;}.lips { position: absolute;top: 0;left: 0; width: 116px; height: 24px; border: 1px solid #FFA600; border-bottom-left-radius: 50% 100%;border-bottom-right-radius: 50% 100%;}
CSS3繪製騰訊QQ企鵝

CSS3繪製騰訊QQ企鵝

CSS3繪製騰訊QQ企鵝

基本 head 輪廓就是這樣了,最後在把右眼眼球部分上個色,來進行層疊覆蓋隱藏

.innerRightEye { position: absolute; top: 20px; left: 8px; /* 月牙眼球外輪廓 */ width: 18px; height: 24px; /* border: 1px solid #000; */ border-top-left-radius: 50% 90%; border-top-right-radius: 50% 90%; border-bottom-left-radius: 50% 10%; border-bottom-right-radius: 50% 10%; background: black;box-shadow: 0 -1px 2px black;}.innerRightEye::after { content: ""; position: absolute; bottom: -1px;left: 4px; /* 月牙眼球內部輪廓 */ width: 10px; height: 13px; /* border: 1px solid #000; */ border-top-left-radius: 50% 100%; border-top-right-radius: 35% 80%; background: white;}.fix { position: absolute; top: 19px; width: 4px; height: 4px; /* border: 1px solid #000; */ border-radius: 50%; background: black;}.fix:after{content: ""; position: absolute; top: 0;left: 14px;width: 4px; height: 4px; /* border: 1px solid #000; */ border-radius: 50%; background: black;}
CSS3繪製騰訊QQ企鵝

接下來 開始繪製 QQ 的 body 部分,老樣子對 body 進行層次結構劃分:圍巾、圍巾尾、內輪廓、外輪廓

先各個容器位置佈局好

/* QQ body */.body { /* body 容器定位 */ position: absolute; top: 135px; left: 48px; width: 326px; height: 300px; /* border: 1px solid #000; */}/* QQ body -> scarf */.scarf { position: absolute; top: -2px; left: 34px; width: 258px; height: 110px; border: 1px solid #000; border-top: none;}/* QQ body -> scarfEnd */.scarfEnd { position: absolute; left: 74px; top: 90px;width: 52px; height: 64px; border: 3px solid black;}/* QQ body -> innerWrapper */.innerWrapper { /* innerWrapper 容器定位 */ position: absolute; left: 30px;top: 76px; width: 280px; height: 200px; border: 1px solid #000;}/* QQ body -> outerWrapper */.outerWrapper{ /* outerWrapper 容器定位 */ position: absolute;top: 54px;overflow: hidden; width: 262px;left: 32px; height: 250px; border: 1px solid #000;}
CSS3繪製騰訊QQ企鵝

輪廓線條修正

/* QQ body */.body { /* body 容器定位 */ position: absolute; top: 135px; left: 48px; width: 326px; height: 300px; /* border: 1px solid #000; */}/* QQ body -> scarf */.scarf { position: absolute; top: -2px; left: 34px; width: 258px; height: 110px; border: 1px solid #000; border-top-left-radius: 30px 34px;border-top-right-radius: 38px 34px;border-bottom-left-radius: 50% 76px; border-bottom-right-radius: 50% 76px; border-top: none;}/* QQ body -> scarfEnd */.scarfEnd { position: absolute; left: 74px; top: 90px;width: 52px; height: 64px; border: 3px solid black; border-bottom-left-radius: 50% 43%;border-bottom-right-radius: 15px;border-top-left-radius: 20% 57%;}/* QQ body -> innerWrapper */.innerWrapper { /* innerWrapper 容器定位 */ position: absolute; left: 30px;top: 76px; width: 280px; height: 200px; overflow: hidden;}.inner { position: absolute; left: 25px;top: -71px;width: 218px;height: 210px; border: 1px solid #000; border-radius: 50%;}/* QQ body -> outerWrapper */.outerWrapper{ /* outerWrapper 容器定位 */ position: absolute;top: 54px;overflow: hidden; width: 262px;left: 32px; height: 250px;}.outer{ position: absolute;top: -84px;width: 260px; height: 250px; border: 1px solid #000;border-radius: 125px;}
CSS3繪製騰訊QQ企鵝

大致輪廓基本已經出來了,還有一些內部線條,等後面在來慢慢繪製。

接下來我們來繪製 hand 部分,安裝老路子層次結構劃分:左手、右手; 手的樣子需要通過兩個 div 進行整合才能繪製出來,所以再次劃分: 左手上、左手下、右手上、右手下

/* QQ handWrapper */.handWrapper{ /* 定位手的起始點 */position: absolute;top: 219px;left: 7px;}/* QQ handWrapper -left */.leftHandTopContainer { /* 定位 */position: absolute;top: 55px;left: 50px; width: 118px; height: 26px; border: 1px solid #000;transform-origin: bottom left;transform: rotate(-70deg);}.leftHandBottomContainer { /* 定位 */ position: absolute;top: 78px;left: 50px;width: 100px; height: 30px; border: 1px solid #000;transform-origin: top left;transform: rotate(-70deg);}/* QQ handWrapper -right */.rightHandTopContainer { /* 定位 */ position: absolute;top: 47px;left: 240px; width: 118px; height: 34px; border: 1px solid #000;transform-origin: bottom right; transform: rotate(65deg);}.rightHandBottomContainer{ /* 定位 */ position: absolute;top: 81px; left: 248px;width: 110px;height: 58px; border: 1px solid #000;transform-origin: top right;transform: rotate(90deg);}
CSS3繪製騰訊QQ企鵝

線條輪廓修改

/* QQ handWrapper */.handWrapper{ /* 定位手的起始點 */position: absolute;top: 219px;left: 7px;}/* QQ handWrapper -left */.leftHandTopContainer { /* 定位 */position: absolute;top: 55px;left: 50px; width: 118px; height: 26px; /* border: 1px solid #000; */transform-origin: bottom left; transform: rotate(-70deg); overflow: hidden;}.leftHandTop { /* 上半部分 */width: 128px;height: 54px; border: 1px solid #050346; border-top-left-radius: 44% 38px; border-top-right-radius: 56% 33px;}.leftHandBottomContainer { /* 定位 */ position: absolute;top: 78px;left: 50px;width: 100px; height: 30px; /* border: 1px solid #000; */transform-origin: top left; transform: rotate(-70deg); overflow: hidden;}.leftHandBottom { position: absolute; top: -26px; width: 128px;height: 44px; border: 1px solid #050346; border-bottom-left-radius: 48% 20px;border-bottom-right-radius: 52% 23px;}/* QQ handWrapper -right */.rightHandTopContainer { /* 定位 */ position: absolute;top: 47px;left: 240px; width: 118px; height: 34px; /* border: 1px solid #000; */transform-origin: bottom right; transform: rotate(65deg); overflow: hidden;}.rightHandTop { position: absolute; left: -30px; width: 148px;height: 54px; border: 1px solid #050346; border-top-right-radius: 41% 54px; border-top-left-radius: 59% 48px;}.rightHandBottomContainer{ /* 定位 */ position: absolute;top: 81px; left: 248px;width: 110px;height: 58px; /* border: 1px solid #000; */transform-origin: top right; transform: rotate(90deg); overflow: hidden;}.rightHandBottom { position: absolute;top: 1px;left: 38px; width: 68px;height: 28px; border: 1px solid #000; border-bottom-right-radius: 100% 40px;}
CSS3繪製騰訊QQ企鵝

是不是漂亮很多了, 那快點把腳的部分也完成吧,和手的結構基本類似。

基礎位置佈局

/* QQ footerWrapper */.footWrapper{ /* 定位起始點 */position: absolute;top: 292px; left: 80px; width: 300px; height: 80px; border: 1px solid #000;}/* QQ footerWrapper -> left */.leftFootTopWrapper { /* 定位左腳上容器 */ position: absolute;top: 16px;left: -1px; width: 130px; height: 37px; border: 1px solid #000;}.leftFootBottomWrapper { position: absolute; top: 52px;left: -1px;width: 130px;height: 38px; border: 1px solid #000;}/* QQ footerWrapper -> right */.rightFootTopWrapper { /* 定位左腳上容器 */ position: absolute;top: 22px;left: 134px; width: 130px; height: 38px; border: 1px solid #000;}.rightFootBottomWrapper { position: absolute; top: 52px;left: 134px;width: 134px; height: 38px; border: 1px solid #000;}
CSS3繪製騰訊QQ企鵝

輪廓調整

/* QQ footerWrapper */.footWrapper{ /* 定位起始點 */position: absolute;top: 292px; left: 80px; width: 300px; height: 80px; /* border: 1px solid #000; */}/* QQ footerWrapper -> left */.leftFootTopWrapper { /* 定位左腳上容器 */ position: absolute;top: 16px;left: -1px; width: 130px; height: 37px; /* border: 1px solid #000; */ overflow: hidden;}.leftFootTop { position: absolute;top: -10px; left: 3px; width: 120px;height: 60px; border: 4px solid black; border-top-left-radius: 80% 70%;}.leftFootBottomWrapper { position: absolute; top: 52px;left: -1px;width: 130px;height: 38px; /* border: 1px solid #000; */ overflow: hidden;}.leftFootBottom { position: absolute; top: -30px;left: 3px; width: 120px;height: 60px; border: 4px solid #000; border-top-left-radius: 50% 44%;border-top-right-radius: 50% 44%;border-bottom-left-radius: 50% 56%;border-bottom-right-radius: 50% 56%;}/* QQ footerWrapper -> right */.rightFootTopWrapper { /* 定位左腳上容器 */ position: absolute;top: 22px;left: 134px; width: 130px; height: 38px; /* border: 1px solid #000; */ overflow: hidden;}.rightFootTop { position: absolute; top: 0px;left: 4px; width: 120px;height: 60px; border: 4px solid black; border-top-right-radius: 32% 65%;}.rightFootBottomWrapper { position: absolute; top: 52px;left: 134px;width: 134px; height: 38px; /* border: 1px solid #000; */ overflow: hidden;}.rightFootBottom { position: absolute; top: -30px;left: 3px; width: 120px;height: 60px; border: 4px solid #000; border-top-left-radius: 50% 56%;border-top-right-radius: 50% 56%;border-bottom-left-radius: 50% 44%;border-bottom-right-radius: 50% 44%;}
CSS3繪製騰訊QQ企鵝

基本整體框架結構就出來了,開始上色吧。上色的過程可以幫助我們調整z-index,也就是各個模塊的重疊層次,遮蓋了一些無用的線條和框角。

  1. head 開始
 /* QQ head */.head { position: absolute; top: 18px; left: 96px; width: 234px; height: 185px; border: 1px solid #000; border-top-left-radius: 117px 117px; border-top-right-radius: 117px 117px; border-bottom-left-radius: 117px 68px; border-bottom-right-radius: 117px 68px; background: #000;}/* QQ head -> eye */.eye { position: absolute; width: 44px; height: 66px; border:1px solid #000; border-radius: 50% 50%; background: #fff;}.left.eye { left: 62px; top: 50px;}.right.eye { left: 132px; top: 50px;}.innerLeftEye { position: absolute; top: 20px; left: 20px; width: 18px; height: 24px; border-radius: 50%; border: 1px solid #000; background: #000;}.innerLeftEye::after { content: ""; position: absolute; top: 6px; left: 9px; width: 6px; z-index: 11; height: 8px; /* border: 1px solid #000; */ border-radius: 50%; background: #fff;}.innerRightEye { position: absolute; top: 20px; left: 8px; /* 月牙眼球外輪廓 */ width: 18px; height: 24px; /* border: 1px solid #000; */ border-top-left-radius: 50% 90%; border-top-right-radius: 50% 90%; border-bottom-left-radius: 50% 10%; border-bottom-right-radius: 50% 10%; background: black; box-shadow: 0 -1px 2px black;}.innerRightEye::after { content: ""; position: absolute; bottom: -1px;left: 4px; /* 月牙眼球內部輪廓 */ width: 10px; height: 13px; /* border: 1px solid #000; */ border-top-left-radius: 50% 100%; border-top-right-radius: 35% 80%; background: #FFF;}.fix { position: absolute; top: 19px; width: 4px; height: 4px; /* border: 1px solid #000; */ border-radius: 50%; background: #000;}.fix:after{content: ""; position: absolute; top: 0;left: 14px;width: 4px; height: 4px; /* border: 1px solid #000; */ border-radius: 50%; background: black;}/* QQ head -> mouth */.mouthTopContainer { /* 定位 */ position: absolute; top: 120px; left: 39px; z-index: 1; width: 158px; height: 29px; overflow: hidden; /* 隱藏超出部分 */}.mouthTop { /* 上嘴唇輪廓 */ position: absolute; top: 0; left: 0; z-index: 1; width: 158px; height: 34px; border: 1px solid #FFA600; border-top-left-radius: 45% 34px; border-top-right-radius: 45% 34px; background: #FFA600;}.mouthBottomContainer { position: absolute; top: 146px; left: 39px; z-index: 1; width: 158px; height: 15px; overflow: hidden; /* 隱藏超出部分 */}.mouthBottom { position: absolute; top: -4px; left: 0; z-index: 1; width: 158px; height: 24px; border: 1px solid #FFA600; border-top:none; border-bottom-left-radius: 45% 24px; border-bottom-right-radius: 45% 24px; background: #FFA600;}/* 嘴唇上下層次感-咬合部位 */.lispContainer { /* 定位 */ position: absolute;top: 146px;left: 60px; width: 116px; height: 24px;}.lips { position: absolute;top: 0;left: 0; width: 116px; height: 24px; border: 1px solid #FFA600; border-bottom-left-radius: 50% 100%; border-bottom-right-radius: 50% 100%; background: #FFA600;}
CSS3繪製騰訊QQ企鵝

  1. body
/* QQ body */.body { /* body 容器定位 */ position: absolute; top: 135px; left: 48px; width: 326px; height: 300px; /* border: 1px solid #000; */}/* QQ body -> scarf */.scarf { position: absolute; top: -2px; left: 34px; z-index: 5; width: 258px; height: 110px; border: 1px solid #000; border-top-left-radius: 30px 34px;border-top-right-radius: 38px 34px;border-bottom-left-radius: 50% 76px; border-bottom-right-radius: 50% 76px; border-top: none; background: #FB0009;}/* QQ body -> scarfEnd */.scarfEnd { position: absolute; left: 74px; top: 90px;width: 52px; height: 64px; border: 3px solid black; border-bottom-left-radius: 50% 43%;border-bottom-right-radius: 15px; border-top-left-radius: 20% 57%; background: #FB0009;}/* QQ body -> innerWrapper */.innerWrapper { /* innerWrapper 容器定位 */ position: absolute; left: 30px;top: 76px; width: 280px; height: 200px; overflow: hidden;}.inner { position: absolute; left: 25px;top: -71px;width: 218px;height: 210px; border: 1px solid #000; border-radius: 50%; background: #fff;}/* QQ body -> outerWrapper */.outerWrapper{ /* outerWrapper 容器定位 */ position: absolute;top: 54px;overflow: hidden; width: 262px;left: 32px; height: 250px;}.outer{ position: absolute;top: -84px;width: 260px; height: 250px; border: 1px solid #000; border-radius: 125px; background: #000;}
CSS3繪製騰訊QQ企鵝

上色後你會發現,有的圖層顯示先後順序不對,需要調整下先後順序。

  • head > body
  • body裡(scafEnd > inner > outer)
CSS3繪製騰訊QQ企鵝

  1. hand
/* QQ handWrapper -left */.leftHandTopContainer { /* 定位 */position: absolute;top: 55px;left: 50px; width: 118px; height: 26px; /* border: 1px solid #000; */transform-origin: bottom left; transform: rotate(-70deg); overflow: hidden;}.leftHandTop { /* 上半部分 */width: 128px;height: 54px; border: 1px solid #050346; border-top-left-radius: 44% 38px; border-top-right-radius: 56% 33px; background: #000;}.leftHandBottomContainer { /* 定位 */ position: absolute;top: 78px;left: 50px;width: 100px; height: 30px; /* border: 1px solid #000; */transform-origin: top left; transform: rotate(-70deg); overflow: hidden;}.leftHandBottom { position: absolute; top: -26px; width: 128px;height: 44px; border: 1px solid #050346; border-bottom-left-radius: 48% 20px; border-bottom-right-radius: 52% 23px; background: #000;}/* QQ handWrapper -right */.rightHandTopContainer { /* 定位 */ position: absolute;top: 47px;left: 240px; width: 118px; height: 34px; /* border: 1px solid #000; */transform-origin: bottom right; transform: rotate(65deg); overflow: hidden;}.rightHandTop { position: absolute; left: -30px; width: 148px;height: 54px; border: 1px solid #050346; border-top-right-radius: 41% 54px; border-top-left-radius: 59% 48px; background: #000;}.rightHandBottomContainer{ /* 定位 */ position: absolute;top: 81px; left: 248px;width: 110px;height: 58px; /* border: 1px solid #000; */transform-origin: top right; transform: rotate(90deg); overflow: hidden;}.rightHandBottom { position: absolute;top: 1px;left: 38px; width: 68px;height: 28px; border: 1px solid #000; border-bottom-right-radius: 100% 40px; background: #000;}
  1. footer
/* QQ footerWrapper */.footWrapper{ /* 定位起始點 */position: absolute;top: 292px; left: 80px; width: 300px; height: 80px; /* border: 1px solid #000; */}/* QQ footerWrapper -> left */.leftFootTopWrapper { /* 定位左腳上容器 */ position: absolute;top: 16px;left: -1px; width: 130px; height: 37px; /* border: 1px solid #000; */ overflow: hidden;}.leftFootTop { position: absolute;top: -10px; left: 3px; width: 120px;height: 60px; border: 4px solid black; border-top-left-radius: 80% 70%; background: #FF9C00;}.leftFootBottomWrapper { position: absolute; top: 52px;left: -1px;width: 130px;height: 38px; /* border: 1px solid #000; */ overflow: hidden;}.leftFootBottom { position: absolute; top: -30px;left: 3px; width: 120px;height: 60px; border: 4px solid #000; border-top-left-radius: 50% 44%;border-top-right-radius: 50% 44%;border-bottom-left-radius: 50% 56%; border-bottom-right-radius: 50% 56%; background: #FF9C00;}/* QQ footerWrapper -> right */.rightFootTopWrapper { /* 定位左腳上容器 */ position: absolute;top: 22px;left: 134px; width: 130px; height: 38px; /* border: 1px solid #000; */ overflow: hidden;}.rightFootTop { position: absolute; top: 0px;left: 4px; width: 120px;height: 60px; border: 4px solid black; border-top-right-radius: 32% 65%; background: #FF9C00;}.rightFootBottomWrapper { position: absolute; top: 52px;left: 134px;width: 134px; height: 38px; /* border: 1px solid #000; */ overflow: hidden;}.rightFootBottom { position: absolute; top: -30px;left: 3px; width: 120px;height: 60px; border: 4px solid #000; border-top-left-radius: 50% 56%;border-top-right-radius: 50% 56%;border-bottom-left-radius: 50% 44%; border-bottom-right-radius: 50% 44%; background: #FF9C00;}
CSS3繪製騰訊QQ企鵝

到了這裡基本完成了 90% 了, 剩下的就是線條優化,使 QQ 看起來更有層次感、立體感。

嘴唇

嘴巴的形狀不夠性感、立體;繪製一個斜邊三角形,修復嘴唇的層次感。

CSS3繪製騰訊QQ企鵝

繪製這樣一個斜邊三角形,步驟分解如圖所示:

CSS3繪製騰訊QQ企鵝

先是繪製一個普通三角形,通過逆時針旋轉得到一個修復三角形,那麼相對稱的修復三角形可以通過使用rotateY,繞著Y軸旋轉180度,來得到。

/* 嘴唇上下層次感-咬合部位 */.lispContainer { /* 定位 */ position: absolute;top: 146px;left: 60px; width: 116px; height: 24px;}.lips { position: absolute;top: 0;left: 0; width: 116px; height: 24px; border: 1px solid #FFA600; border-bottom-left-radius: 50% 100%; border-bottom-right-radius: 50% 100%; background: #FFA600;}.lipShadow { position: absolute; width: 0px; height: 0px; border-top: 20px solid transparent;border-bottom: 20px solid transparent;border-right: 8px solid black;transform-origin: top right; transform: rotate(-60deg); z-index: 2;}.lipShadow.left { top: 4px; left: -12px; transform: rotate(-60deg);}.lipShadow.right { top: 4px; left: 111px; transform: rotate(60deg) rotateY(180deg);}
CSS3繪製騰訊QQ企鵝

圍巾

圍脖竟然沒摺痕,不立體; 通過繪製一個“小尾巴”來進行美化

CSS3繪製騰訊QQ企鵝

border-right: 6px solid black;width: 100px;height: 70px;border-bottom-right-radius: 70px 70px;

當對一個角應用圓角樣式,如果這個角相鄰的兩個border一個有定義而一個無定義,那麼繪製的結果就是由粗到細的“小尾巴了”。[在整個繪製過程中,同一個圖形它的繪製方法有很多種,例如一個矩形可以用 width x height構成,也可以由border x height(width)構成,甚至可以由border組合(width = height = 0)構成,根據情況選擇吧。]

/* QQ body -> scarf */.scarf { position: absolute; top: -2px; left: 34px; z-index: 5; width: 258px; height: 110px; border: 4px solid #000; border-top-left-radius: 30px 34px;border-top-right-radius: 38px 34px;border-bottom-left-radius: 50% 76px; border-bottom-right-radius: 50% 76px; border-top: none; background: #FB0009;}.scarfShadowLeft { position: absolute; top: 0px;left: 6px;width: 60px; height: 70px; /* border: 4px solid #000; */ border-top: 6px solid #000;border-top-left-radius: 90px 120px; border-top-right-radius: 30px 30px;transform: rotate(-79deg);}.scarfShadowRight { position: absolute; top: 8px;left: 143px;width: 100px; height: 70px; /* border: 4px solid #000; */ border-right: 6px solid black;width: 100px; border-bottom-right-radius: 70px 70px; border-right: 6px solid black;}/* QQ body -> scarfEnd */.scarfEnd { position: absolute; left: 74px; top: 90px;width: 52px; height: 64px; border: 3px solid black; border-bottom-left-radius: 50% 43%;border-bottom-right-radius: 15px; border-top-left-radius: 20% 57%; background: #FB0009; z-index: 4;}.scarfEndShadow { position: absolute; top: 6px;left: 12px;width: 20px; height: 20px; /* border: 4px solid #000; */ border-top: 6px solid #000; border-top-left-radius: 30px 30px; transform-origin: top right; transform: skewX(4deg) scaleY(1.5) rotate(-60deg);}
CSS3繪製騰訊QQ企鵝

也是通過繪製小尾巴來進行美化

/* QQ footerWrapper */.footWrapper{ /* 定位起始點 */position: absolute;top: 292px; left: 80px; width: 300px; height: 80px; /* border: 1px solid #000; */}.toe { position: absolute;width: 25px;height: 20px; /* border: 4px solid #000; */ border-top: 4px solid black; border-top: 4px solid black; border-top-right-radius: 30px 30px; border-top-left-radius: 10px 10px; transform-origin: top left; z-index: 10;}/* QQ footerWrapper -> left */.leftFootTopWrapper { /* 定位左腳上容器 */ position: absolute;top: 16px;left: -1px; width: 130px; height: 37px; /* border: 1px solid #000; */ overflow: hidden;}.leftFootTop { position: absolute;top: -10px; left: 3px; width: 120px;height: 60px; border: 4px solid black; border-top-left-radius: 80% 70%; background: #FF9C00;}.toe.left { top: 50px; left: 2px; transform: rotate(-45deg);}.leftFootBottomWrapper { position: absolute; top: 52px;left: -1px;width: 130px;height: 38px; /* border: 1px solid #000; */ overflow: hidden;}.leftFootBottom { position: absolute; top: -30px;left: 3px; width: 120px;height: 60px; border: 4px solid #000; border-top-left-radius: 50% 44%;border-top-right-radius: 50% 44%;border-bottom-left-radius: 50% 56%; border-bottom-right-radius: 50% 56%; background: #FF9C00;}/* QQ footerWrapper -> right */.rightFootTopWrapper { /* 定位左腳上容器 */ position: absolute;top: 22px;left: 134px; width: 130px; height: 38px; /* border: 1px solid #000; */ overflow: hidden;}.rightFootTop { position: absolute; top: 0px;left: 4px; width: 120px;height: 60px; border: 4px solid black; border-top-right-radius: 32% 65%; background: #FF9C00;}.toe.right { top: 50px; left: 264px; transform: rotate(45deg) rotateY(180deg);}.rightFootBottomWrapper { position: absolute; top: 52px;left: 134px;width: 134px; height: 38px; /* border: 1px solid #000; */ overflow: hidden;}.rightFootBottom { position: absolute; top: -30px;left: 3px; width: 120px;height: 60px; border: 4px solid #000; border-top-left-radius: 50% 56%;border-top-right-radius: 50% 56%;border-bottom-left-radius: 50% 44%; border-bottom-right-radius: 50% 44%; background: #FF9C00;}
CSS3繪製騰訊QQ企鵝

大功告成,一個生動的 QQ 企鵝就繪製完了~

介紹下這個過程中幾個比較典型的圖形繪製方法:

1、企鵝的眼睛:橢圓,直接設置border-radius:50% 50%; 即可[因為寬高分別為44px和66px,所以也可以這樣設定:border-radius: 22px / 33px]

2、圍脖的尾部:一個圓角各異的矩形,所以這裡需要對幾個角分別設定border-radius,微調的結果為

border-bottom-left-radius: 50% 43%;border-bottom-right-radius: 15px;border-top-left-radius: 20% 57%;

3、企鵝的胳膊:手的繪製較為麻煩一點,可以分為上下兩個部分,將繪製的結果拼接到一起。那麼對於不需要的部分怎麼辦呢?我們可以將上(下)部分放到一個div(container)中,利用overflow:hidden的屬性來截取所要的部分。繪製複雜圖形的時候常用的方法就是切割和拼接,將圖形切割成一個個簡單的小塊,通過層疊和旋轉變化進行組合。

使用transform:rotate(deg)的時候,優先設定transform-origin屬性,會比較方便。設定的點作為中心點,整個圖形繞著這個點進行角度變化。例如:transform-origin:bottom left, 使用左下角作為原點。也可以使用具體的像素值和百分比。

在基本的框架線條中比非常多的使用了border-radius用於構造各種曲線條,小企鵝是圓圓胖胖的,:)


分享到:


相關文章: