css繪製卡券優惠券 三步用CSS寫乙個商城卡券

2021-10-13 11:32:18 字數 2773 閱讀 7137

今天是618 ,各大**都在搞**活動,今天我們就來用css做乙個**卡捲,具體如下:

還在為上面這樣格式各樣的**卡券的樣式而發愁?css 不熟,canvas 太難,怎麼辦?

用 css 寫乙個**卡券需要幾步?

一共需要三步:

交給測試後,我們來分析下 css 卡券。

我們來準備一下基礎知識

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 是可以設定多個的,遵循 background: [background-color] [background-image] [background-repeat] [background-attachment] [background-position] / [ background-size] [background-origin] [background-clip]; 使用 , 隔開即可。

開始組合基礎知識

寫乙個最簡單的

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

.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;

進一步學習

你可還記得 background 是有 repeat 屬性嗎?也就是說我們只要設定一部分樣式,再使用 repeat 即可,看下,這不就是乙個不漸變的 linear-gradient 和 radial-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;

複雜一點

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

.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;

css繪製卡券優惠券 CSS 實現優惠券樣式

本文將介紹如何使用 css 中的 radial gradient 實現如下圖所示的優惠券樣式效果 繪製基本樣式 首先,我們繪製出優惠券的基本樣式,這很簡單,就不多說了。滿 100 減 30 scss voucher width 600px height 200px display flex left...

css繪製卡券優惠券 如何使用css建立乙個優惠券

需求場景 新增優惠券類目,展示使用者的優惠券 常見的設計樣式如下圖,核心為半圓 分步拆解 網上有幾種方案 一種是boder clip的形式,裁剪出4個小半圓角,拼湊在一起 一種是radial gradient徑向漸變,相對上一種需要考慮其相容性 一種是使用背景,特點是載入稍慢,體驗比css差,相容性...

css3製作優惠券

demo stamp stamp stamp before stamp after stamp i stamp par stamp par p stamp par span stamp par sign stamp par sub stamp copy stamp copy p stamp01 st...