[css]我要用css畫幅畫(一),css幅畫

來源:互聯網
上載者:User

[css]我要用css畫幅畫(一),css幅畫

幾年前開始就一直想用css畫幅畫。

今天才真正開始, 從簡單的開始。

 

作為一個工作壓力那麼大的程式員,我首先要畫一個太陽。

html如下:

1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>Css Paint</title> 6 <link rel="stylesheet" type="text/css" href="css/style.css"> 7 </head> 8 <body> 9 <div class="sun">10 <div class="sun-body"></div>11 <div class="sun-shine-light sun-shine-light1"></div>12 <div class="sun-shine-light sun-shine-light2"></div>13 <div class="sun-shine-light sun-shine-light3"></div>14 <div class="sun-shine-light sun-shine-light4"></div>15 <div class="sun-shine-light sun-shine-light5"></div>16 </div>17 </body>18 </html>View Code

 

css如下:

1 .sun{ 2 position: relative; 3 } 4 5 .sun-body{ 6 background-color: red; 7 border-radius: 50%; 8 height: 300px; 9 left: -100px;10 position: absolute;11 top: -100px;12 width: 300px;13 z-index: 9;14 }15 .sun-shine-light{16 background-color: yellow;17 height: 5px;18 left:250px;19 margin-top:30px;20 position: relative;21 width: 300px;22 z-index:10;23 }24 .sun-shine-light1{25 -webkit-transform: rotate(-3deg);26 -moz-webkit-transform: rotate(-3deg);27 -ms-webkit-transform: rotate(-3deg);28 -o-webkit-transform: rotate(-3deg);29 }30 .sun-shine-light2{31 top: 70px;32 left: 240px;33 -webkit-transform: rotate(10deg);34 -moz-webkit-transform: rotate(10deg);35 -ms-webkit-transform: rotate(10deg);36 -o-webkit-transform: rotate(10deg);37 }38 .sun-shine-light3{39 top: 160px;40 left: 195px;41 -webkit-transform: rotate(30deg);42 -ms-transform: rotate(30deg);43 -o-transform: rotate(30deg);44 transform: rotate(30deg);45 }46 .sun-shine-light4{47 top: 215px;48 left: 85px; 49 width: 260px;50 -webkit-transform: rotate(55deg);51 -ms-transform: rotate(55deg);52 -o-transform: rotate(55deg);53 transform: rotate(55deg);54 }55 .sun-shine-light5{56 top: 200px;57 left: -50px;58 width: 230px;59 -webkit-transform: rotate(85deg);60 -ms-transform: rotate(85deg);61 -o-transform: rotate(85deg);62 transform: rotate(85deg);63 }View Code

 

依照@魔芋鈴的建議, 以下是效果的連結(再次感謝):

效果

 

這裡用到一個比較陌生的css屬性: transform:rotate(Ndeg)  

作用是旋轉,其中N為整數,表示旋轉的角度。旋轉基於對象的重心。

 

心得:

當對象尺寸(長寬)改變時,旋轉的重心也會跟著改變,被這個特性折騰了不少時間。

在上面的光線旋轉了一定角度後,寬度看起來會變長一點。於是又修改它的width,然後相應的left、top都需要修改了(因為重心位置變了)。

 

今天就到這。以後繼續。 謝謝觀看。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.