国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > CSS > 正文

三步用CSS寫一個商城卡券

2024-07-11 09:00:04
字體:
供稿:網(wǎng)友

今天是618 ,各大商城都在搞促銷活動,今天我們就來用css做一個商城卡卷,具體如下:

 

還在為上面這樣格式各樣的商城卡券的樣式而發(fā)愁?CSS 不熟,canvas 太難,怎么辦?

用 CSS 寫一個商城卡券需要幾步?

一共需要三步:

  • 打開這個網(wǎng)址(瀏覽器輸入 https://qishaoxuan.github.io/css_tricks/hollowOut/ )
  • 找到需要的樣式
  • 復(fù)制粘貼

交給測試后,我們來分析下 CSS 卡券。

我們來準(zhǔn)備一下基礎(chǔ)知識

radial-gradien:

background: radial-gradient(shape size at position, start-color, ..., last-color);

描述
shape 確定圓的類型: 
ellipse (默認): 指定橢圓形的徑向漸變。 circle :指定圓形的徑向漸變
size 定義漸變的大小
position 定義漸變的位置

這樣,我們能很容易寫出一個居中的圓形背景圖

.center-circle {    width: 100px;    height: 100px;    background: radial-gradient(circle at 50px 50px, transparent 10px, #00adb5 0);  }

linear-gradient

background: linear-gradient(direction, color-stop1, color-stop2, ...);

描述
direction 用角度值指定漸變的方向(或角度)
color-stop1, color-stop2,... 用于指定漸變的起止顏色

我們不需要知道具體的漸變過程,只要寫一個簡單的,寫一個使用漸變屬性而不漸變背景圖即可:

.linear-gradient {    width: 100px;    height: 100px;    background: linear-gradient(to right, #00adb5, #00adb5);  }

background

background 是可以設(shè)置多個圖片的,遵循 background: [background-color] [background-image] [background-repeat] [background-attachment] [background-position] / [ background-size] [background-origin] [background-clip]; 使用 , 隔開即可。

開始組合基礎(chǔ)知識

寫一個最簡單的

只要把上述中心圓示例的圓形位置定位在左側(cè)即可

.left-circle{  width: 100px;  height: 100px;  position: relative;  background: radial-gradient(circle at 0 50px, transparent 10px, #00adb5 0) top left/100px 100% no-repeat;}

進一步學(xué)習(xí)

你可還記得 background 是有 repeat 屬性嗎?也就是說我們只要設(shè)置一部分樣式,再使用 repeat 即可,看下圖片,這不就是一個不漸變的 linear-gradientradial-gradient 的組合嗎,再借助偽類,我們即可寫出來了。

.hollow-circles {  width: 300px;  height: 100px;  position: relative;  background: #00adb5;  margin-bottom: 10px;}.hollow-circles::after {  content: '';  position: absolute;  height: 5px;  width:100%;  left: 0;  bottom: -5px;  background-image: linear-gradient(to right, #00adb5 5px, transparent 5px, transparent),  radial-gradient(10px circle at 10px 5px, transparent 5px, #00adb5 5px);  background-size: 15px 5px;}

復(fù)雜一點

看見很簡單,不就是剛才那個圓再畫一個嗎,但是要考慮到兩側(cè)的顏色是不同的,所以我們需要畫四個背景圖才行,將每個圓定位在方形的各個角落,然后組合在一起即可。

.two-circles {  width: 300px;  height: 100px;  background: radial-gradient(circle at right top, transparent 10px, #00adb5 0) top left / 60px 51% no-repeat,    radial-gradient(circle at right bottom, transparent 10px, #00adb5 0) bottom left /60px 51% no-repeat,    radial-gradient(circle at left top, transparent 10px, #eeeeee 0) top right /240px 51% no-repeat,    radial-gradient(circle at left bottom, transparent 10px, #eeeeee 0) bottom right /240px 51% no-repeat;}

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持武林網(wǎng)。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 拜城县| 右玉县| 禹城市| 沙洋县| 湟中县| 灵台县| 内黄县| 苏尼特左旗| 平罗县| 报价| 驻马店市| 容城县| 尼木县| 琼结县| 卢氏县| 苍山县| 隆化县| 鹤庆县| 广昌县| 贵南县| 铁岭县| 临潭县| 桃源县| 红原县| 墨脱县| 砀山县| 濮阳市| 凤山县| 万荣县| 綦江县| 长春市| 上饶市| 乌拉特后旗| 涞源县| 罗江县| 洞头县| 蚌埠市| 东乌珠穆沁旗| 松江区| 勃利县| 青州市|