This article brings you relevant knowledge about gradients, shadows and filters in css, including linear gradients, radial gradients, conical gradients and other related issues. I hope it will be helpful to everyone helpful.
Recommended learning: css video tutorial
1. First introduction to CSS gradient
CSS Gradient is a special type of image
represented by gradient
, consisting of a gradual transition between two or more colors.
Three gradient types:
- Linear: created by the
linear-gradient()
function - Radial: created by
radial -gradient()
function creates - Cone: created by
conic-gradient()
function
ps: You can also use repeating- The linear-gradient()
and repeating-radial-gradient()
functions create repeating gradients.
Gradient can be used anywhere image
is used, such as in the background.
2. CSS linear gradient
2.1 Introduction to linear gradient
-
Instructions
- To create a linear gradient, just Just specify two colors. These are called color stops. Specify at least two color stops. You can also set the starting point and direction (or angle) and the gradient effect.
-
Syntax
background-image: linear-gradient(direction(方向), color1(颜色值), color2(颜色值), ...);
2.2 Linear Gradient Application
2.2.1 Linear gradient - from top to bottom (default)
-
Code example
<style> .box { width: 300px; height: 100px; background-image: linear-gradient(red, yellow); }</style> <p></p>
The effect is as follows
- Code example
background-image: linear-gradient(to right, red, yellow);
- The effect is as follows
##2.2. 3 Linear Gradient - Diagonal
- Code Example
-
background-image: linear-gradient(to bottom right, red, yellow);
- The effect is as follows
2.2.4 Linear Gradient - Set Angle
- Description
-
If If you want more precise control over the direction of the gradient, you can set a specific angle for the gradient.
- When using angles, 0deg
- represents the gradient direction from bottom to top,
90deg
represents the gradient direction from left to right, and other positive angles are normal. clockwise direction. And a negative angle means counterclockwise.
Code example -
background-image: linear-gradient(180deg, red, yellow);
- The effect is as follows
2.2.5 Linear Gradient - Using Multiple Color Stops
- Code Example
-
background-image: linear-gradient(red, yellow, green);
- The effect is as follows
##2.2.6 Linear gradient - Repeat linear gradient
-
repeating-linear-gradient()
- The function is used to repeat linear gradients.
-
background-image: repeating-linear-gradient(red, yellow 10px);
- The effect is as follows
3. CSS radial gradient
-
A radial gradient is similar to a linear gradient, except that the radial gradient radiates outward from the center point.
- You can specify the location of the center point, and you can also set them to be circular or elliptical.
-
background-image: radial-gradient(shape(设置形状,默认为椭圆形), size(最远角), position(中心), color1(颜色值), color2(颜色值));
-
<style> .box { width: 300px; height: 100px; background-image: radial-gradient(red, yellow, green); }</style> <p></p>
- The effect is as follows
Code example
-
background-image: radial-gradient(red 10%, yellow 20%, green 50%);
- The effect is as follows
Code example
-
/* 设置为圆形形状 */background-image: radial-gradient(circle, red 10%, yellow 20%, green 50%);
- The effect is as follows
##3.2.4 Radial Gradient-Set the center of the gradient
- You can position the center of the gradient using keywords, percentages or absolute length, length and percentage value repetitions if there is only one, otherwise in order of position from left to right.
-
- Code example
background-image: radial-gradient(at 10% 30%, red 10%, yellow 20%, green 50%);
3.2.5 径向渐变-重复径向渐变
-
代码示例
background-image: repeating-radial-gradient(black, black 5px, #fff 5px, #fff 10px);
效果如下
四、CSS 圆锥渐变
4.1 介绍圆锥渐变
-
说明
- 圆锥渐变类似于径向渐变,两者均为圆形,并使用元素的中心作为色标的源点。
- 它是围绕中心点按照扇形方向进行旋转的渐变。
-
语法
background-image: conic-gradient(from angle(表示起始的角度,默认为从上到下) at position(设置圆锥中心点的位置), start-color(定义开始颜色), stop-color(定义结束颜色))
4.2 圆锥渐变的应用
4.2.1 圆锥渐变-顺时针方向旋转(默认方式)
-
代码示例
<style> .box { width: 300px; height: 300px; background-image: conic-gradient(red,yellow); }</style> <p></p>
效果如下
4.2.2 圆锥渐变-设置渐变的中心点
-
代码示例
background-image: conic-gradient(at 30% 20%, red,yellow);
效果如下
4.2.3 圆锥渐变-使用多个色标
-
代码示例
background-image: conic-gradient(red, orange, yellow, green, teal, blue, purple);
-
效果如下
4.2.4 圆锥渐变-重复圆锥渐变
-
代码示例
background-image: repeating-conic-gradient(red 10%, yellow 20%);
效果如下
五、CSS 渐变补充知识
5.1 创建实线
-
说明
- 要在不同颜色之间创建一条单一的硬线,即不同颜色的颜色不是不同的,可以将不同的位置颜色设置为相同
-
代码示例
background: linear-gradient(to bottom left, red 50%, yellow 50%);
效果如下
5.2 使用透明度
-
说明
- 如需添加透明度,我们使用 rgba() 函数来定义色标。 rgba() 函数中的最后一个参数可以是 0 到 1 的值,它定义颜色的透明度:0 表示全透明,1 表示全彩色(无透明)。
- 也可以使用
transparent
参数,代表全透明。
-
代码示例
background-image: linear-gradient(to right, transparent, red);
效果如下
CSS 阴影
一、初识 CSS 阴影
CSS阴影主要的作用是可以让页面中的文字和元素具有立体的效果,从而被突出出来。
两种阴影属性:
-
box-shadow
:用于给元素添加阴影 -
text-shadow
:用于给文本添加阴影
ps:还有一个 filter
滤镜的函数drop-shadow()
也可以添加阴影,它主要用于给透明图像的非透明部分添加阴影效果。
二、box-shadow
属性
2.1 介绍box-shadow
属性
-
说明
- 用于在元素的框架上添加阴影效果,还可以在同一个元素上设置多个阴影效果,用逗号隔开。
-
语法
box-shadow: OffsetX(水平偏移), OffsetY(垂直偏移), Blur(模糊半径), Spread(扩展距离,阴影的尺寸), Color(阴影颜色), Position(阴影位置,默认在外部(outset));
2.2 box-shadow
属性的应用
2.2.1 box-shadow
属性-基本使用
-
代码示例
<style> .box { width: 300px; height: 300px; background-color: yellow; box-shadow: 10px 10px; }</style> <p></p>
效果如下
2.2.2 box-shadow
属性-多重阴影与定向阴影
-
代码示例
box-shadow: -5px 0 5px 0px #000, 0 -5px 5px 0px #000;
效果如下
2.2.3 box-shadow
属性-模拟边框
-
代码示例
box-shadow: 0px 0px 0px 10px #000, 0px 0px 0px 20px red;
-
效果如下
2.2.4 box-shadow
属性-内阴影
-
代码示例
box-shadow: 0px 0px 30px 10px red inset;
-
效果如下
三、text-shadow
属性
3.1 介绍text-shadow
属性
-
说明
- 为文字添加阴影,也可以添加多个阴影,用逗号隔开。
-
语法
text-shadow: OffsetX(水平偏移), OffsetY(垂直偏移), Blur(模糊半径), Color(阴影颜色));
-
注意
-
text-shadow
没有扩展距离属性值,阴影位置属性值。
-
3.2 text-shadow
属性的应用
3.2.1 text-shadow
属性-基本使用
-
代码示例
<style> .box { width: 300px; height: 300px; background-color: yellow; text-shadow: 0px 0px 5px red; }</style> <p>hello world</p>
效果如下
text-shadow
属性基本与box-shadow
属性一样,就不多举例了
CSS 滤镜
一、初识 CSS 滤镜
滤镜
这两个字我相信大家都很熟悉,平时爱自拍,拍照的同学肯定都会打开滤镜修饰一下图片吧,那么CSS滤镜也是这样,直接用filter
属性来修饰图像。
二、CSS 滤镜方法
-
blur():模糊
- 可以任何长度单位,值为 0 显示原图,值越大越模糊
-
brightness():亮度
- 百分比,可用 0~1 代替,值为 0 显示全黑,值为 100% 显示原图
-
contrast():对比度
- 百分比,可用 0~1 代替,值为 0 显示全黑,值为 100% 显示原图
-
drop-shadow():阴影
-
说明
- 与
box-shadow
属性类似 - 没有内阴影效果
- 不能阴影叠加
- 与
-
代码示例
/* 代码示例 */ <style> .box1 { width: 300px; height: 300px; border: 3px solid red; box-shadow: 5px 5px 10px 0 black; } .box2 { width: 300px; height: 300px; border: 3px solid red; filter: drop-shadow(5px 5px 10px black); } </style> <p></p> <p></p>
-
-
grayscale():灰度
- 百分比,可用 0~1 代替,值为 0 显示原图,值为 100% 显示全灰
-
hue-rotate():色相旋转
- 角度,值为 0 显示原图,值为 0~360deg 减弱原图色彩,
-
invert():反相
- 百分比,可用 0~1 代替,值为 0 显示原图,值为 100% 完全反转原图色彩
-
opacity():透明度
- 百分比,可用 0~1 代替,值为 0 显示透明,值为 100% 显示原图
-
saturate():饱和度
- 百分比,可用 0~1 代替,值为 0 完全不饱和原图,值为 100% 显示原图
-
sepia():褐色
- 百分比,可用 0~1 代替,值为 0 显示原图,值为 100% 显示褐色
三、CSS 滤镜的应用
3.1 CSS滤镜-将图片设置为灰色
-
代码示例
<style> .box { filter: grayscale(1); }</style> <p> <img src="/static/imghwm/default1.png" data-src="./imgs/1.jpg" class="lazy" alt="A detailed look at CSS gradients, shadows, and filters" > </p>
效果如下
具体的滤镜调制方法可以参照CSSgram的官网进行学习
The above is the detailed content of A detailed look at CSS gradients, shadows, and filters. For more information, please follow other related articles on the PHP Chinese website!

CSS Grid is a powerful tool for creating complex, responsive web layouts. It simplifies design, improves accessibility, and offers more control than older methods.

Article discusses CSS Flexbox, a layout method for efficient alignment and distribution of space in responsive designs. It explains Flexbox usage, compares it with CSS Grid, and details browser support.

The article discusses techniques for creating responsive websites using CSS, including viewport meta tags, flexible grids, fluid media, media queries, and relative units. It also covers using CSS Grid and Flexbox together and recommends CSS framework

The article discusses the CSS box-sizing property, which controls how element dimensions are calculated. It explains values like content-box, border-box, and padding-box, and their impact on layout design and form alignment.

Article discusses creating animations using CSS, key properties, and combining with JavaScript. Main issue is browser compatibility.

Article discusses using CSS for 3D transformations, key properties, browser compatibility, and performance considerations for web projects.(Character count: 159)

The article discusses using CSS gradients (linear, radial, repeating) to enhance website visuals, adding depth, focus, and modern aesthetics.

Article discusses pseudo-elements in CSS, their use in enhancing HTML styling, and differences from pseudo-classes. Provides practical examples.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

WebStorm Mac version
Useful JavaScript development tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Zend Studio 13.0.1
Powerful PHP integrated development environment

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function
