按下右側的「點擊預覽」按鈕在當前頁面預覽,點擊連接全屏預覽。css
https://codepen.io/zhang-ou/pen/YLqbXyhtml
此視頻是能夠交互的,你能夠隨時暫停視頻,編輯視頻中的代碼。git
請用 chrome, safari, edge 打開觀看。github
https://scrimba.com/c/cPvn6tEchrome
請從 github 下載。佈局
定義一個名爲 box 的容器:動畫
<div class="box"> </div>
內容居中顯示:ui
html, body { height: 100%; display: flex; align-items: center; justify-content: center; }
畫條紋背景:spa
.box { width: 300px; height: 300px; background: linear-gradient( -45deg, white 0%, white 25%, hotpink 25%, hotpink 50%, white 50%, white 75%, hotpink 75%, hotpink 100%); background-size: 10%; }
在 box 容器內定義一個名爲 content 的容器:
<div class="box"> <div class="content"> </div> </div>
box 容器留出厚邊框,content 容器嵌在其中:
.box .content { height: 100%; display: flex; align-items: center; justify-content: center; } .box { box-sizing: border-box; padding: 15px; } .box .content { background-color: white; }
設置厚邊框的立體效果:
.box, .box .content { box-shadow: 0 0 2px deeppink, 0 0 5px rgba(0, 0, 0, 1), inset 0 0 5px rgba(0, 0, 0, 1); border-radius: 10px; }
content 容器中增長內容:
<div class="box"> <div class="content"> <h2>What is Lorem Ipsum?</h2> <p>Mauris volutpat risus quis nisi tempus hendrerit. Nullam nisi urna, suscipit quis risus sed, congue congue quam. Morbi sit amet suscipit ex. Vivamus vel nulla ac libero volutpat ultrices.</p> </div> </div>
內容佈局:
.box .content { flex-direction: column; box-sizing: border-box; padding: 30px; text-align: center; font-family: sans-serif; } .box .content h2 { color: deeppink; } .box .content p { color: dimgray; }
定義動畫效果:
@keyframes animate { from { background-position: 0; } to { background-position: 10%; } }
最後,把動畫效果應用到 box 容器上:
.box { animation: animate 2s linear infinite; }
大功告成!