Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS CSS Basics (2014) Enhancing the Design With CSS Transparent Gradients and Multiple Backgrounds

SeHyun Choi
SeHyun Choi
3,441 Points

How do I apply CSS transparent gradient on top of image?

Instead of doing

background:linear-gradient (#ffa949, transparent 90%), #ffa949 url ('../img/mountains.jpg') no-repeat center;

I prefer doing background-image:url('../image/mountain.jpg'); background-size:cover; background-repeat:no-repeat;

but I don't know how I would apply transparent gradient on top of image doing this way. Please help!

2 Answers

Steven Parker
Steven Parker
231,248 Points

You can specify comma-separated images:

  background-image: linear-gradient(#ffa949, transparent 90%), url('../img/mountains.jpg');

This is effectively what's happening when you use the "background" shorthand.

Martha Fontelera
Martha Fontelera
1,556 Points

Hello Steven, does that mean that if you use the 'deg' value, it automatically starts the gradient at the bottom? I am really confused with the degree value. Thanks in advance.

Steven Parker
Steven Parker
231,248 Points

The direction specifies where the "end" of the gradient will be. So 0 degrees (0deg) would be the same as "to top" (bottom to top). And the default is 180deg (top to bottom).

A few experiments might be much more enlightening than explanations. Give it a try.