Start your free trial now, and begin learning software, business and creative skills—anytime, anywhere—with video instruction from recognized industry experts.

Start Your Free Trial Now

Mixing gradients with transparency


From:

CSS: Gradients

with Justin Seeley

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.
please wait ...
Watch the Online Video Course CSS: Gradients
1h 13m Beginner Feb 15, 2013

Viewers: in countries Watching now:

Join Justin Seeley as he introduces gradients, a somewhat hidden strength of CSS that allows you to add depth and texture to your web designs while reducing load times—creating a better viewing experience for your visitors versus static images. Discover how to create simple linear and radial gradients; apply them to backgrounds, buttons, and text; and write browser-specific syntax to ensure your designs look the same across multiple platforms. The course also shows how to create metallic textures, diagonal gradients, and repeatable patterns. Along the way, Justin demonstrates real-world uses for gradients and techniques to extend them beyond the basics.

Topics include:
  • Exploring browser compatibility
  • Creating horizontal and vertical gradients
  • Adding extra color stops
  • Exploring radial gradient syntax
  • Using transparency
  • Creating fallbacks
  • Generating gradients via the web
Subject:
Web
Software:
CSS
Author:
Justin Seeley

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.

There are currently no FAQs about CSS: Gradients.

 
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

* Estimated file size

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

Upgrade to View Courses Offline

login

With our new Desktop App, Annual Premium Members can download courses for Internet-free viewing.

Upgrade Now

After upgrading, download Desktop App Here.

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 ?

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:

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.

Learn more, save more. Upgrade today!

Get our Annual Premium Membership at our best savings yet.

Upgrade to our Annual Premium Membership today and get even more value from your lynda.com subscription:

“In a way, I feel like you are rooting for me. Like you are really invested in my experience, and want me to get as much out of these courses as possible this is the best place to start on your journey to learning new material.”— Nadine H.

Start your FREE 10-day trial

Begin learning software, business, and creative skills—anytime,
anywhere—with video instruction from recognized industry experts.
lynda.com provides
Unlimited access to over 4,000 courses—more than 100,000 video tutorials
Expert-led instruction
On-the-go learning. Watch from your computer, tablet, or mobile device. Switch back and forth as you choose.
Start Your FREE Trial Now
 

A trusted source for knowledge.

 

We provide training to more than 4 million people, and our members tell us that lynda.com helps them stay ahead of software updates, pick up brand-new skills, switch careers, land promotions, and explore new hobbies. What can we help you do?

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.