效果
- 鼠標觸碰按鈕,出現(xiàn)水墨風(fēng)格動畫
- 屏幕自適應(yīng)
- 一份html文件聪廉,一份css文件,無javascript,上手程度:很簡單
筆記
:root
這個 CSS 偽類匹配文檔樹的根元素夺巩。對于 HTML 來說,:root 表示元素周崭,除了優(yōu)先級更高之外柳譬,與 html 選擇器相同。
box-sizing
屬性允許您以特定的方式定義匹配某個區(qū)域的特定元素续镇。
content-box:在寬度和高度之外繪制元素的內(nèi)邊距和邊框美澳。
border-box:在寬度和高度之內(nèi)繪制元素的內(nèi)邊距和邊框。
inherit:從父元素繼承
顏色漸變linear-gradient
背景漂亮的深藍-淺藍效果就是這個的作用摸航。具體請看developer.mozilla.org/zh-CN/docs/…
- calc()
此CSS函數(shù)讓你在聲明CSS屬性值時執(zhí)行一些計算制跟。它可以用在如下場合:、, 酱虎、雨膨、、或读串。
flex:
這是一種可以自動適應(yīng)不同屏幕尺寸的布局界面聊记。下面的justify-content和align-items規(guī)定了應(yīng)用flex布局的子元素的排列方式
justify-content:設(shè)置或檢索彈性盒子元素在主軸(橫軸)方向上的對齊方式。通俗一點就是左右方向恢暖。
align-items:設(shè)置或檢索彈性盒子元素在側(cè)軸(縱軸)方向上的對齊方式排监。通俗一點就是上下方向。
@media:
媒體查詢杰捂,簡單來說就是可以讓網(wǎng)頁自動適應(yīng)不同的設(shè)備屏幕尺寸社露。例如上面意為當屏幕寬度小于750px時,就讓flex的方向改為縱軸排列琼娘。
rem:
是一個相對單位峭弟,相對根元素字體大小的單位附鸽,再直白點就是相對于html元素字體大小的單位。用px這種絕對單位固然方便瞒瘸,但當屏幕尺寸改變坷备,就沒看看全了。rem則是一種相對單位情臭,根據(jù)父元素的變化而變化省撑,解決了自適應(yīng)的問題。
cubic-bezier:
貝塞爾曲線俯在,用來生成水墨效果的關(guān)鍵竟秫。
源碼:
html代碼
web前端開發(fā)學(xué)習(xí)Q-q-u-n: 731771211,分享學(xué)習(xí)的方法和需要注意的小細節(jié)跷乐,不停更新最新的教程和學(xué)習(xí)方法(詳細的前端項目實戰(zhàn)教學(xué)視頻肥败,PDF)
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<title>CSS3 水墨風(fēng)格背景動畫按鈕DEMO演示</title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<svg width="0" height="0">
<filter id="filter">
<feTurbulence type="fractalNoise" baseFrequency=".01" numOctaves="6" />
<feDisplacementMap in="SourceGraphic" scale="100" />
</filter>
</svg>
<div class="wrapper">
<div class="button _1"> <span>hover</span>
<div class="back"></div>
</div>
<div class="button _2"> <span>hover</span>
<div class="back"></div>
</div>
<div class="button _3"> <span>hover</span>
<div class="back"></div>
</div>
<div class="button _4"> <span>hover</span>
<div class="back"></div>
</div>
</div>
<div style="text-align:center;clear:both;">
<script src="/gg_bd_ad_720x90.js" type="text/javascript"></script>
<script src="/follow.js" type="text/javascript"></script>
</div>
</body>
</html>
css代碼:
web前端開發(fā)學(xué)習(xí)Q-q-u-n: 731771211,分享學(xué)習(xí)的方法和需要注意的小細節(jié)愕提,不停更新最新的教程和學(xué)習(xí)方法(詳細的前端項目實戰(zhàn)教學(xué)視頻馒稍,PDF)
:root {
--height: 100px;
--width: 200px;
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
width: 100%;
height: 100vh;
background-image: linear-gradient(to right, #4facfe 0%, #00f2fe 100%);
font-family: sans-serif;
}
.wrapper {
width: calc(4 * var(--width));
height: calc(4 * var(--height));
display: flex;
justify-content: center;
align-items: center;
}
.button {
position: relative;
width: calc(0.8 * var(--width));
height: calc(0.7 * var(--height));
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
overflow: hidden;
margin: 0 0.8rem;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2), 0 3px 8px rgba(0, 0, 0, 0.1);
transition: all 0.3s cubic-bezier(0, 0.22, 0.3, 1);
}
.button:before {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.1);
}
.button span {
color: #fff;
font-size: 1rem;
z-index: 10;
text-transform: uppercase;
letter-spacing: 2px;
}
.button._1 {
background: #2980b9;
}
.button._2 {
background: #8e44ad;
}
.button._3 {
background: #16a085;
}
.button._4 {
background: #e74c3c;
}
.button .back {
position: absolute;
width: 0;
height: 0;
filter: url(#filter);
border-radius: 50%;
z-index: 5;
transition: all 2.5s cubic-bezier(0.1, 0.22, 0.3, 1);
}
.button._1 .back {
left: -50%;
top: -50%;
background: #27ae60;
}
.button._2 .back {
right: -50%;
top: -50%;
background: #c0392b;
}
.button._3 .back {
left: -50%;
bottom: -50%;
background: #34495e;
}
.button._4 .back {
right: -50%;
bottom: -50%;
background: #2980b9;
}
.button:hover .back {
width: calc(2 * var(--width));
height: calc(2 * var(--height));
}
@media only screen and (max-width: 750px) {
.wrapper {
flex-direction: column;
}
.button {
margin: 0.8rem 0;
}
}