lt;div class="sector"></div>
.sector{
width: 200px;
height: 200px;
border-radius: 200px;
background-color: deepskyblue;
position: relative;
}
.sector::before{
content: "";
width: 200px;
height: 200px;
position: absolute;
background-color: white;
border-radius: 200px;
/*裁減半圓,再做旋轉*/
clip: rect(0px,100px,200px,0);
transform: rotate(-60deg);
}
.sector::after{
content: "";
width: 200px;
height: 200px;
position: absolute;
background-color: white;
border-radius: 200px;
/*裁減半圓,再做旋轉*/
clip: rect(0px,200px,200px,100px);
transform: rotate(60deg);
}
方式二
<>
<style>
#demo {
position: relative;
width: 50px;
height: 50px;
overflow: hidden;
}
#circle {
position: absolute;
width: 100px;
height: 100px;
background-color: black;
border-radius: 50%;
}
</style>
<body>
<div id="demo">
<div id="circle"></div>
</div>
</body>
</>
方式三
一天
1.用js寫一個隨機生成指定字符串的方法。
2.給定一個span標簽,用純css并且用3種方式實現(xiàn)一個三角形。
第二天
1.用至少3種方式實現(xiàn)數(shù)組去重。
2.給定一個div標簽,用純css實現(xiàn)一個水波動畫(2種方法)。
(用::before和::after偽對象也可以實現(xiàn))
我自己是一名從事了多年開發(fā)的web前端老程序員,目前辭職在做自己的web前端私人定制課程,今年年初我花了一個月整理了一份最適合2019年學習的web前端學習干貨,各種框架都有整理,送給每一位前端小伙伴,想要獲取的可以關注我的頭條號并在后臺私信我:前端,即可免費獲取。
第三天
1.js實現(xiàn)一個深拷貝和淺拷貝。
2.給定一個div標簽,用3種方式實現(xiàn)其子元素水平垂直居中。
【周末福利打卡】
1.用css畫一個立方體。
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <style> .container { position: relative; width: 300px; height: 300px; margin: 120px auto; transform-style: preserve-3d; transform: rotateX(-33.5deg) rotateY(45deg); transform-origin: 150px 150px; animation: rotate 3s infinite; } .container .page { position: absolute; width: 200px; height: 200px; text-align: center; line-height: 200px; color: #fff; } .container .page:first-child { background-color: rgba(0,0,0,.2); } .container .page:nth-child(2) { transform: rotateX(90deg); transform-origin: 0 0; transition: transform 3s; background-color: rgba(179, 15, 64, 0.6); } .container .page:nth-child(3) { transform: translateZ(200px); background-color: rgba(22, 160, 137, 0.7); } .container .page:nth-child(4) { transform: rotateX(-90deg); transform-origin: -200px 200px; background-color: rgba(210, 212, 56, 0.2); } .container .page:nth-child(5) { transform: rotateY(-90deg); transform-origin: 0 0; background-color: rgba(201, 23, 23, 0.6); } .container .page:nth-child(6) { transform: rotateY(-90deg) translateZ(-200px); transform-origin: 0 200px; background-color: rgba(16, 149, 182, 0.2); } @keyframes rotate { 0% { transform: rotateX(-33.5deg) rotateY(45deg); } 100% { transform: rotateX(-33.5deg) rotateY(405deg); } } </style> </head> <body> <div class="container"> <div class="page">A</div> <div class="page">B</div> <div class="page">C</div> <div class="page">D</div> <div class="page">E</div> <div class="page">F</div> </div> </body> </html>
2. 用js正則實現(xiàn)去除文本中的html標簽。
第五天
1.用promise封裝一個自己的ajax庫。
思路大致是這樣的,你們也可以根據(jù)業(yè)務自己封裝更復雜的ajax庫,比如添加請求響應攔截器
2.用css實現(xiàn)footer固定在底部的效果(至少2種方法)。
第六天
1.判斷一個字符串中出現(xiàn)次數(shù)最多的字符,統(tǒng)計這個次數(shù)
2. 對 BFC 規(guī)范(塊級格式化上下文:block formatting context)的理解
第七天
1.用js實現(xiàn)判斷設備類型以及瀏覽器類型
2. 用至少2種方法實現(xiàn)css定位中fixed(固定定位)的效果
其次,用定位也可以實現(xiàn)。
第八天
1.用js實現(xiàn)一個可以自定義格式的時間函數(shù)
2. 用css實現(xiàn)一個進度條動畫
用css3實現(xiàn)驚艷面試官的背景即背景動畫(高級附源碼)
第九天
1. 用js計算斐波那契數(shù)列的第n項
2. 用css畫一個扇形
css實現(xiàn)扇形可以用偽類矩形旋轉一個角度,來遮擋父容器的圓形,父容器溢出隱藏。
第十天
1. 解釋一下在js里,0.1+0.2為什么等于0.30000000000000004,如何通過代碼解決這個問題?
原文鏈接:https://mp.weixin.qq.com/s/kqk7ZUNvUp0EDvVNYpq8yw
作者:趣談前端
近每天都帶一個蘋果加餐,有次吃到一個十分漂亮的紅蘋果,突然覺得,可以試著畫一個蘋果看看。
之前確實無法想象,可以使用CSS能畫出一個蘋果。
先看效果:
你沒有看錯,這個不是真蘋果。僅僅一百多行代碼就可以實現(xiàn)的CSS的紅蘋果。我自己看到最終效果都驚呆了。
第一步畫出蘋果的輪廓:
.apple {
position: relative;
width: 300px;
height: 270px;
background-color: #bf2934;
border-radius: 160px 150px 145px 150px/160px 140px 210px 190px;
}
第二步:將蘋果變得更加立體
1)右上角使用亮色內陰影,畫出高光效果
2)左下角使用兩層暗色內陰影,畫出背光的暗色效果
3)左上角增加一個亮色高光
4)整體增加徑向漸變的背景,將重心高光,四周暗色
.apple {
position: relative;
width: 300px;
height: 270px;
background: radial-gradient(#0000, rgba(0, 0, 0, .1)),
radial-gradient(rgba(239, 156, 109, .2), #0000);
background-color: #bf2934;
border-radius: 160px 150px 145px 150px/160px 140px 210px 190px;
box-shadow: inset 30px -20px 30px 20px rgba(0, 0, 0, .15),
inset 10px -10px 15px 0 rgba(0, 0, 0, .15),
inset 10px 10px 5px 0 rgba(255, 255, 255, .05),
inset -10px 10px 30px 10px rgba(237, 115, 84, .3);
}
第三步:增加光源反光的高亮效果
使用before偽元素,畫一個亮色的橢圓。橘色的陰影。然后整體模糊一下
.apple::before {
position: absolute;
left: 135px;
top: 50px;
content: '';
width: 80px;
height: 30px;
transform: skew(-20deg) rotate(10deg);
border-radius: 45%;
background: rgba(255, 255, 255, .65);
box-shadow: 2px 10px 30px 22px rgba(239, 156, 109, 1);
filter: blur(5px);
}
哇,一不小心,畫出來了一個西紅柿
好吧,這個時候, 我其實可以停下來,先發(fā)一篇畫西紅柿的文章了。
第四步:準備一下頂部葉柄的凹陷
這個凹陷效果使用after偽元素,畫一個黑色透明色漸變的橢圓,然后使用clip-path,截取頂部扇形部分。
.apple::after {
position: absolute;
left: 90px;
top: 2px;
width: 120px;
background: radial-gradient(rgba(0, 0, 0, .3), rgba(239, 156, 109, .2));
height: 30px;
content: '';
border-radius: 50%;
filter: blur(2px);
clip-path: polygon(50% 55%, 150% 0, -50% 0);
filter: blur(1px);
}
真是一個漂亮的西紅柿。。。。。。。
蘋果和西紅柿的區(qū)別,主要是,蘋果沒有那么的光滑,顏色沒有這么完美。我們需要一些雜色。
第五步:增加雜色條紋
好吃的蘋果,都有縱向的條紋雜色。這里我們是模糊后的border來模擬。由于需要很多雜色,這里使用js添加,稍微做點隨機。
.stripe {
position: absolute;
width: 300px;
height: 270px;
border-radius: 160px 150px 145px 150px/160px 140px 210px 190px;
border-right: solid 2px rgba(239, 156, 109, .2);
transform: scaleX(.9);
filter: blur(4px);
}
function addStripe() {
var fragment = document.createDocumentFragment()
var count = 15
for (var i = -count; i < count; i++) {
var stripe = document.createElement('div')
stripe.className = 'stripe'
stripe.style.opacity = Math.max(1, 0.5 + Math.random())
stripe.style.transform = `scaleX(${(i / count + Math.random() * 0.2).toFixed(2)})`
fragment.appendChild(stripe)
}
document.querySelector('.apple').appendChild(fragment)
}
是不是突然就像蘋果了
第六步:增加噪點
好吃的蘋果,會有很多小小的斑點。這里,我們使用js增加一些隨機的斑點。
.spot {
position: absolute;
width: 4px;
height: 4px;
border-radius: 50%;
background: rgba(239, 156, 109, .6);
filter: blur(1px);
}
function addSpot() {
var count = 60
var fragment = document.createDocumentFragment()
for (var i = 0; i < count; i++) {
var spot = document.createElement('div')
spot.className = 'spot'
spot.style.left = 5 + ~~(Math.random() * 90) + '%'
spot.style.top = 5 + ~~(Math.random() * 90) + '%'
spot.style.opacity = 0.2 + Math.random() * 0.4
spot.style.transform = `scaleX(${Math.random() * 0.8 + 0.2}) scaleY(${Math.random() * 0.8 + 0.2}) rotate(${~~(360 * Math.random())}deg)`
fragment.appendChild(spot)
}
document.querySelector('.apple').appendChild(fragment)
}
蘋果變得更加誘人了。
再做一些細節(jié)優(yōu)化。
第七部:給蘋果加個葉柄。
買過西瓜的都知道,葉柄是證明西瓜新鮮與否的標志。蘋果亦然。
.petiole {
position: absolute;
transform: translate(155px, -48px) rotate(35deg);
width: 20px;
height: 60px;
border-top: solid 15px transparent;
border-left: solid 10px rgb(162, 76, 9);
border-bottom: solid 8px transparent;
border-radius: 50%;
}
.petiole.left {
transform: translate(154px, -49px) rotate(35deg);
border-left-color: rgb(123, 48, 24);
}
<div class="apple">
<div class="petiole left"></div>
<div class="petiole"></div>
</div>
是不是新鮮很多。
最后,我們給蘋果加個陰影,看著更加立體一點。
.shadow {
position: absolute;
width: 300px;
height: 270px;
background-color: rgba(0, 0, 0, .15);
transform-origin: 50% 100%;
transform: translate(5px, 5px) skew(60deg) scaleY(.25);
border-radius: 160px 150px 145px 150px/160px 140px 210px 190px;
box-shadow: 0 0 20px rgba(0, 0, 0, .15);
filter: blur(4px);
}
嬌艷欲滴的大蘋果,完成?。。。?/p>
代碼倉庫地址:
https://github.com/shb190802/html5
演示地址:
http://suohb.com/demo/win/apple.html
*請認真填寫需求信息,我們會在24小時內與您取得聯(lián)系。