Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use css to make a background image "fade" or gradient the bottom portion to transparent so that a background color shows?

Tags:

I know that this can easily be done in any image editing program, I was just curious if there was a way just using css.

Example:

body {background-color: #837960; background-image: url("Images/background.jpg") background-repeat: no-repeat;}

Could you use css to fade the background image into the background color so a visible line does not exist or should I keep adding a gradient to transparency in Photoshop?

like image 329
Chris569x Avatar asked Apr 04 '13 14:04

Chris569x


People also ask

How do you make a transparent gradient image in CSS?

To add transparency, we use the rgba() function to define the color stops. The last parameter in the rgba() function can be a value from 0 to 1, and it defines the transparency of the color: 0 indicates full transparency, 1 indicates full color (no transparency).

Can you add gradient to image in CSS?

CSS gradients allow us to display smooth transitions between two or more colours. They can be added on top of the background image by simply combining the background-image URL and gradient properties.

How do I change the background gradient in CSS?

The linear-gradient() function sets a linear gradient as the background image. To create a linear gradient you must define at least two color stops. Color stops are the colors you want to render smooth transitions among. You can also set a starting point and a direction (or an angle) along with the gradient effect.


1 Answers

It is possible - in CSS3 you can set multiple values for background

body {
    background: #837960 url("https://i.stack.imgur.com/MUsp6.jpg") 0 0 no-repeat;

    background: -moz-linear-gradient(top, rgba(255,255,255,0) 0%, rgba(130,91,0,1) 100%);   /* FF3.6+ */
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(255,255,255,0)), color-stop(100%,rgba(130,91,0,1))); /* Chrome,Safari4+ */
    background: -webkit-linear-gradient(top, rgba(255,255,255,0) 0%,rgba(130,91,0,1) 100%); /* Chrome10+,Safari5.1+ */
    background: -o-linear-gradient(top, rgba(255,255,255,0) 0%,rgba(130,91,0,1) 100%); /* Opera 11.10+ */
    background: -ms-linear-gradient(top, rgba(255,255,255,0) 0%,rgba(130,91,0,1) 100%); /* IE10+ */
    background: linear-gradient(to bottom, rgba(255,255,255,0) 0%,rgba(130,91,0,1) 100%); /* W3C */
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#00ffffff', endColorstr='#825b00',GradientType=0 ); /* IE6-9 */
}

However, it will work only in modern browser that supports CSS3

(code generated via http://www.colorzilla.com/gradient-editor/)

like image 56
Lemurr Avatar answered Apr 27 '23 23:04

Lemurr