search
HomeWeb Front-endCSS TutorialUse CSS3 to implement background color gradient

This articleIntroductionUsing CSS3 to achieve background color gradient

CSS gradient color concept:

CSS gradient color (Gradients) allows us to use a color gradient The effect modifies a space - transitioning from one color to another - filling the space. There are two forms of gradient colors: linear (linear gradient) and radial (circular gradient). It is obvious that CSS gradient color (Gradients) technology produces a visual pattern effect, and achieving this visual effect is very simple and can be achieved through simple programming. CSS gradients were introduced very early in CSS3, but the promotion of this technology took a long time.

Basic syntax of CSS gradient technology:

Unified code format

background-image: linear-gradient(<point> || <angle>,]? <stop>, <stop> [, <stop>]*)

The first parameter is the gradient starting point or angle. The second parameter is a color stop. At least two colors are required (starting point and end point), and you can add any color to increase the richness of the color gradient. The definition of the color stop point can be a color, or a color plus a percentage:

/*  color-stop(percentage/amount, color) */
color-stop(0.20, red)

The following code Basically covers all situations of top-down color gradients:

{	/* 底色 */
	background-color: #063053;
	/* chrome 2+, safari 4+; multiple color stops */
	background-image:-webkit-gradient(linear, left bottom, left top, color-stop(0.32, #063053), 
     color-stop(0.66, #395873), color-stop(0.83, #5c7c99));
	/* chrome 10+, safari 5.1+ */
	background-image: -webkit-linear-gradient(#063053, #395873, #5c7c99);	
     /* firefox; multiple color stops */
	background-image: -moz-linear-gradient(top,#063053, #395873, #5c7c99);	
     /* ie 6+ */
	filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=&#39;#063053&#39;, endColorstr=&#39;#395873&#39;);
	/* ie8 + */
     -ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr=&#39;#063053&#39;, endColorstr=&#39;#395873&#39;)";	
     /* ie10 */
	background-image: -ms-linear-gradient(#063053, #395873, #5c7c99);
	/* opera 11.1 */
	background-image: -o-linear-gradient(#063053, #395873, #5c7c99);
	/* 标准写法 */
	background-image: linear-gradient(#063053, #395873, #5c7c99);
}

CSS gradient color (Gradients) technology also supports gradient directions with angles, such as 45-degree angle gradient:

/* fallback */
	background-color:#063053;
	/* chrome 2+, safari 4+; multiple color stops */
	background-image:-webkit-gradient(linear, left bottom, right top, color-stop(0.32, #063053), 
     color-s top(0.66, #395873), color-stop(0.83, #5c7c99));
	/* chrome 10+, safari 5.1+ */
	background-image:-webkit-linear-gradient(45deg, #063053, #395873, #5c7c99);
	/* firefox; multiple color stops */
	background-image:-moz-linear-gradient(45deg, #063053, #395873, #5c7c99);
	/* ie10 */
	background-image: -ms-linear-gradient(45deg, #063053 0%, #395873 100%);
	/* opera 11.1 */
	background-image: -o-linear-gradient(45deg, #063053, #395873);
	/* The "standard" */
	background-image: linear-gradient(45deg, #063053, #395873);
}

CSS color gradient (Gradients) technology is valuable, but sometimes difficult to implement. Sometimes you've already implemented the gradient you want, and browser support can become an issue. Here are some suggestions for using CSS color gradients (Gradients):

  • Want your CSS color gradients (Gradients) to show a certain degree of transparency? Use rgba colors.

  • Use the background color as the bottom to prevent you from accidentally not having any color when the browser does not support it.

  • Firefox and Google Chrome both support repeating-linear-gradient and repeating-radial-gradient. The usage is:

background-image: -moz-repeating-linear-gradient(top left -45deg, green, red 5px, white 5px, #ccc 10px);

background-image: -webkit-repeating-linear-gradient(-45deg, green, red 5px, white 5px, #ccc 10px);

Effect:

Basic color linear gradient, top to bottom

使用CSS3实现背景颜色渐变

Basic color linear gradient, 45 degree angle (Chrome, Safari, Firefox, IE10, Opera)

使用CSS3实现背景颜色渐变

The above is the detailed content of Use CSS3 to implement background color gradient. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
What is CSS Grid?What is CSS Grid?Apr 30, 2025 pm 03:21 PM

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

What is CSS flexbox?What is CSS flexbox?Apr 30, 2025 pm 03:20 PM

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.

How can we make our website responsive using CSS?How can we make our website responsive using CSS?Apr 30, 2025 pm 03:19 PM

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

What does the CSS box-sizing property do?What does the CSS box-sizing property do?Apr 30, 2025 pm 03:18 PM

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.

How can we animate using CSS?How can we animate using CSS?Apr 30, 2025 pm 03:17 PM

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

Can we add 3D transformations to our project using CSS?Can we add 3D transformations to our project using CSS?Apr 30, 2025 pm 03:16 PM

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

How can we add gradients in CSS?How can we add gradients in CSS?Apr 30, 2025 pm 03:15 PM

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

What are pseudo-elements in CSS?What are pseudo-elements in CSS?Apr 30, 2025 pm 03:14 PM

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

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function