Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Mixing gradients with transparency

From: CSS: Gradients

Video: Mixing gradients with transparency

One of the things we haven't talked about yet is how do we mix in transparency with gradients, and so, in this example we are going to be taking a look at a page that's styled with the background of just a gigantic image. And so I will jump over in to the web browser and take a look at this image, and so basically what I want to do, is I want to actually simulate some sort of like dark effect that sort of just covers the top part of this and fades gradually into the image, making the image a little bit more dramatic, if you will. This is something that's easily accomplished in something like Photoshop, but in some cases you might not have access to that, but you might just want something that loads a little bit quicker and that you can do on-the-fly and you can change at a moment's notice, and so that's where gradients come in really handy And so what I am going to do is go back over into my code editor for a moment, and what we are going to do is we are just going to make some changes to this.

Mixing gradients with transparency

One of the things we haven't talked about yet is how do we mix in transparency with gradients, and so, in this example we are going to be taking a look at a page that's styled with the background of just a gigantic image. And so I will jump over in to the web browser and take a look at this image, and so basically what I want to do, is I want to actually simulate some sort of like dark effect that sort of just covers the top part of this and fades gradually into the image, making the image a little bit more dramatic, if you will. This is something that's easily accomplished in something like Photoshop, but in some cases you might not have access to that, but you might just want something that loads a little bit quicker and that you can do on-the-fly and you can change at a moment's notice, and so that's where gradients come in really handy And so what I am going to do is go back over into my code editor for a moment, and what we are going to do is we are just going to make some changes to this.

And so the first thing I am going to do is I am going to take this URL section of the background element. I am just going to push that down to another line, and then we'll just tab it over so that it meets right here where my normal arguments would go. And so what I am going to do here is just type out webkit-linear gradient. Of course if you are working in Mozilla or any other browser, you'd put that prefix for moz, ms or Opera with an o in front of that, but in this case since I am just working in webkit for now for demonstration purposes, I am just going to use the webkit syntax for now.

So webkit-linear-gradient, I want this to first start out as black and then I want that to go to transparent, and let's move that to 25%, so that way it moves 25% along the width of the gradient, and put a comma after the parentheses and then we've got our URL, and at the bottom here these are very important to have on there as well, background-repeat, no-repeat, background-attachment: fixed. Both of these will help to make sure that the gradient just goes from top to bottom and does not repeat several different times down the page.

So once we have that done, I am going to go back over into my browser and refresh, and watch the top here. See that gradient goes right there and the transparent part actually starts 25% of the way down the height of the browser. And so I can go back in now anytime I want without having to go back in Photoshop or anything else. I can go back in and I can simply change where that gradient starts to change what this image looks like. So if I go back over into this code window and change this to something like 70% and save it and go back and Refresh, watch what happens to the image; much more gradual fade.

A very nice effect on the image itself. Let's say for instance that the client comes back to me and says "you know what, we don't like how dark the image is at the top." That's okay, I don't have to go back into Photoshop, I'll just change this from black to white or whatever color they want, and so that would change like that. Now you will notice the middle of this looks a little muddy and that is because when you type out the transparent property right there, it's actually referring to transparent black. So it's giving you an RGBA value of 000 and then an alpha value of 0 as well.

So in this case, what we are doing is actually fading white into a transparent black which is accounting for that muddy texture in the middle. Now if you wanted to, you could change this to something like a blue, something like that. Refresh and you can kind of see what it does. You could change this to suit the mood or the look of the photo. Whatever you wanted to do. And another good one would might be something like orange. Let's try that out. Refresh, there we go. Kind of gives us sort of a dusky feel. But in any case, anytime you come back in here you can easily change both the color and the position of the gradient.

You can also change the background if the image falls off or runs out of space, you can change the background color for that, if I wanted that to be black if it was on a larger monitor or something like that. You can also change the image anytime you want, change the position of the gradient, whatever you want, just come back and change that via the code and then refresh your page to see exactly what has happened. And so using transparencies and gradients are actually a great way to simulate some effects that you would otherwise have the jump into an image editing application like Photoshop or even Fireworks to create, and in this case its going to save you a lot of time, and it's going to save you some load time on your pages as well.

Show transcript

This video is part of

Image for CSS: Gradients
CSS: Gradients

23 video lessons · 8859 viewers

Justin Seeley
Author

 

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ.

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Join now "Already a member? Log in

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed CSS: Gradients.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferencesfrom the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Are you sure you want to delete this note?

No

Your file was successfully uploaded.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.