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 Foundations CSS Gradients Linear Gradients

SAMUEL LAWRENCE
PLUS
SAMUEL LAWRENCE
Courses Plus Student 8,447 Points

Can't reverse the gradient color.

Hi for some reason I can't reverse the direction of the gradient using the example Guil showed us in Firefox. I have the latest version. In the example he added the keyword "bottom" before the first color followed by a comma. That's not working for me on Firefox. Did they update it and it now requires a different syntax? Because I noticed that when I used the vendor prefix also for the gradient it didn't work but it worked without the vendor prefix. i.e.

.box {
background: linear-gradient(blue, orange);
}

is there a different syntax for reversing the colors, besides just switching the colors in the parentheses around? This isn't working;

.box {
  background: linear-gradient(bottom, blue, orange)
}

It also doesn't work with the vendor prefix so I left it out in the code example.

However when I use the degrees value it works, but it's producing different results for me. For example

.box {
  background: linear-gradient(0deg, crimson, orange);
}

Gives Guil a horizontal gradient from left to right, but I'm getting a vertical gradient from bottom to top and

.box {
  background: linear-gradient(90deg, crimson, orange);

produces a horizontal gradient from left to right for me but it gives Guil a vertical gradient from top to bottom. I also tried different values like 45deg, 180deg etc and noticed that the gradient begins at the bottom and moves in a clockwise direction and not a counterclockwise direction as Guil stated.

Could someone explain for me what's going on here?

Thanks

2 Answers

Herb Bresnan
Herb Bresnan
10,658 Points

IE 10, Firefox, and Opera 12+ shouldn't need prefixed but the angles and direction work different.

You have to put "to" before the direction. try this: background: linear-gradient(to bottom, blue, orange); to right = starts at left side and goes TO THE RIGHT. to left = starts at the right side and goes TO THE LEFT. to bottom = starts from the top and goes TO THE BOTTOM. to top left = starts from the bottom right to bottom right = starts from the top left.

When using angles: 0 degrees goes from bottom to top CLOCKWISE.

I'm not sure if there is full browser support so it is best to use vendor prefix to be safe.

SAMUEL LAWRENCE
SAMUEL LAWRENCE
Courses Plus Student 8,447 Points

Hi herb thanks for that man. That was driving me crazy. I get it now and it's pretty easy to follow, I mean once you know what to do. Haha. Now I can continue with the lesson. thanks buddy.

Herb Bresnan
Herb Bresnan
10,658 Points

It can get confusing at times. I don't think it's particularly hard, just a lot to remember. Glad you understand it. Have fun.