CSS3實現幾個經常使用的網頁小效果

主題javascript

因爲最近比較忙,本身也沒有很充裕的時間能夠去作比較豐富的分享。今晚我擠出時間來製做這幾個很經常使用的CSS3網頁小效果。最近寫JS的時間比例比較多,不過我仍是比較鍾情於CSS3。因此我仍是堅持分享一些實用的CSS3小例子。此次因爲時間有限,就作了幾個相對比較簡單的例子。看一下吧!css

正文html

第一種效果:java

1

因爲錄製gif圖片會掉幀,因此看起來不流暢,很卡,但其實實際效果仍是不錯的,有彈性一些。web

html代碼:app

<span class="shake"></span>

css代碼:網站

.shake{
    width:40px;
    height:40px;
    display:block;
    background:lightgreen;
    border-radius:50%;
    margin:5px;
    color:#fff;
    font-size:24px;
    text-align:center;
    line-height:40px;
    cursor:pointer;
    -webkit-transition:all 0.25s;
}
.shake:hover{
    -webkit-animation:shake 0.25s;
    background: lightblue;
}
@-webkit-keyframes shake{
    0%,10%,55%,90%,94%,98%,100%{
        -webkit-transform:scale(1,1);
    }
    30%{
        -webkit-transform:scale(1.14,0.86);
    }
    75%{
        -webkit-transform:scale(0.92,1.08);
    }
    92%{
        -webkit-transform:scale(1.04,0.96);
    }
    96%{
        -webkit-transform:scale(1.02,0.98);
    }
    99%{
        -webkit-transform:scale(1.01,0.99);
    }
}

昨晚看到某人的我的博客網站的回到頂部按鈕懸浮效果就是這樣子的,仍是比較有趣的,不過人家的效果可能比個人好一些,你們不妨試一下。spa

第二種效果:3d

2

這種效果其實目前線上不少網站都在用了,無論是使用CSS3,仍是jQuery,都是能夠實現的。那這裏我只是簡單地使用CSS3來實現。code

html代碼:

<input class="search" type="text" placeholder="搜索...">

CSS代碼:

.search{
    width:80px;
    height:40px;
    border-radius:40px;
    border:2px solid lightblue;
    position: absolute;
    right:200px;
    outline:none;
    text-indent:12px;
    color:#666;
    font-size:16px;
    padding:0;
    -webkit-transition:width 0.5s;
}
.search:focus{
    width:200px;
}

通常旁邊都會有一個按鈕,這裏我就不作了。

第三種效果:

3

這種效果也是很經常使用,比較多仍是我的網站偏多。

html代碼:

<div class="banner">
    <a href="javascript:;"></a>
    <span>這是個人我的博客</span>
</div>

css代碼:

.banner{
    width:234px;
    height:34px;
    border-radius:34px;
    position:absolute;
    top:400px;
    left:200px;
}
.banner a{
    display:inline-block;
    width:30px;
    height:30px;
    line-height:30px;
    border-radius:50%;
    border:2px solid lightblue;
    position:absolute;
    left:0px;top:0px;
    background:lightgreen;
    color:#fff;
    text-align:center;
    text-decoration:none;
    cursor:pointer;
    z-index:2;
}
.banner a:hover + span{
    -webkit-transform:rotate(360deg);
    opacity:1;
}
.banner span{
    display:inline-block;
    width:auto;
    padding:0 20px;
    height:34px;
    line-height:34px;
    background:lightblue;
    border-radius:34px;
    text-align: center;
    position:absolute;
    color:#fff;
    text-indent:25px;
    opacity:0;
    -webkit-transform-origin:8% center;
    -webkit-transition:all 1s;
}

第四種效果:

4

這種提示效果就更經常使用了,不少網站都用。

html代碼:

<div class="banner1">
    <a href="javascript:;"></a>
    <span>這是個人我的博客</span>
</div>

css代碼:

.banner1{
    width:234px;
    height:34px;
    border-radius:40px;
    position:absolute;
    top:400px;
    left:600px;
}
.banner1 a{
    display:inline-block;
    width:30px;
    height:30px;
    line-height:30px;
    border-radius:50%;
    border:2px solid lightblue;
    position:absolute;
    left:0px;top:0px;
    background:lightgreen;
    color:#fff;
    text-align:center;
    text-decoration:none;
    cursor:pointer;
    z-index:2;
}
.banner1 a:hover + span{
    -webkit-transform:translateX(40px);
    opacity:1;
}
.banner1 span{
    display:inline-block;
    width:auto;
    padding:0 20px;
    height:30px;line-height:30px;
    background:lightblue;
    border-radius:30px;
    text-align: center;
    color:#fff;
    position:absolute;
    top:2px;
    opacity:0;
    -webkit-transition:all 1s;
    -webkit-transform:translateX(80px);
}

最後一種效果

估計這種就是不經常使用了,本身作着玩,有興趣看一下咯:

5

html結構:

<div class="wrapper">
    <div class="round">
        <span>東邪</span>
        <span>西毒</span>
        <span>南乞</span>
        <span>北丐</span>
    </div>
</div>

css代碼:

.wrapper{
    width:100px;
    height:100px;
    background:lightblue;
    border-radius:50%;
    border:2px solid lightgreen;
    position: absolute;
    top:200px;
    left:400px;
    cursor:pointer;
}
.wrapper:after{
    content:'你猜';
    display:inline-block;
    width:100px;
    height:100px;
    line-height:100px;
    border-radius:50%;
    text-align:center;
    color:#fff;
    font-size:24px;
}
.wrapper:hover .round{
    -webkit-transform:scale(1);
    opacity:1;
    -webkit-animation:rotating 6s 1.2s linear infinite alternate;
}
@-webkit-keyframes rotating{
    0%{
        -webkit-transform:rotate(0deg);
    }
    100%{
        -webkit-transform:rotate(180deg);
    }
}
.round{
    width:240px;
    height:240px;
    border:2px solid lightgreen;
    border-radius:50%;
    position: absolute;
    top:-70px;
    left:-70px;
    -webkit-transition:all 1s;
    -webkit-transform:scale(0.35);
    opacity:0;
}
.round span{
    width:40px;
    height:40px;
    line-height:40px;
    display:inline-block;
    border-radius:50%;
    background:lightblue;
    border:2px solid lightgreen;
    color:#fff;
    text-align:center;
    position:absolute;
}
.round span:nth-child(1){
    right:-22px;
    top:50%;
    margin-top:-22px;
}
.round span:nth-child(2){
    left:-22px;
    top:50%;
    margin-top:-22px;
}
.round span:nth-child(3){
    left:50%;
    bottom:-22px;
    margin-left:-22px;
}
.round span:nth-child(4){
    left:50%;
    top:-22px;
    margin-left:-22px;
}

結語

那麼此次就分享這麼幾個小玩意吧,之後有時間會分享一些比較好的。最後,祝你們七夕節快樂!紅心

 

若需轉載,請註明出處,謝謝合做!

相關文章
相關標籤/搜索