02Geek HTML5 and JavaScript, TypeScript, React, Flash, ActionScript online School
Previous VideoNext Video

The transparent color

At first look the transparent color seams odd but its really powerful mainly when used in combination with the gradient interface in CSS3. In this lecture we will get introduced to the transparent color and see it in action using the almost part of the specifications linear-gradient interface. By the end of this lecture, you will know the transparent color and see it in action.

properties: colors, css3, transparent, linear-gradient

  • It's been around since CSS1
  • has been updated and expanded in every iteration
  • It is now a standalone color
  • Looking at how to use it in action with gradients

Video Transcript

00:00(upbeat music)
00:05- We're still talking about colors,
00:06and the next technical color,
00:08we're back, actually, to named colors.
00:10And this color is transparent.
00:12Why do you need a transparent color, you might ask yourself.
00:15Well, one is you might want to create something
00:16to be transparent, but you could have
00:18just set the alpha to be invisible in that case, right?
00:21Well, in this lecture, we're going to take a look
00:23at the transparent, which was really introduced
00:25already in CSS1, mainly and only for backgrounds.
00:29And every single CSS iteration, it was expanded out
00:32to be able to do more things.
00:34In CSS3 and onward, transparent is a standalone color,
00:38can be used instead of any color,
00:40just like blue, red, or green.
00:42You could just write transparent,
00:43which would create a transparency.
00:45In this lecture, we're going to see
00:46where could it be really useful?
00:48It actually could become incredibly useful
00:51when you're working with gradients.
00:52So, we're going to take a look
00:53at creating a gradient in CSS3,
00:56and integrating into it a transparency.
00:59So, see you in this lecture, really.
01:00Let's get started, let's create a gradient
01:03with a transparency.
01:05Alright, transparent is what we're talking about right now.
01:08If we just go to see it, it is really weird,
01:11and you might think to yourself,
01:12why would anyone ever need to have a transparent color?
01:15It's really a keyword that enables us to put transparency.
01:18So, just make sure that you don't write here
01:20a spelling mistake, which I usually do.
01:23So, for transparent, if I go to my browser,
01:26and I click on refresh, it's gonna support it,
01:29and we can see that in our browser,
01:32all the items that had that color disappeared from view.
01:36It seems useless, right, at first look, but it's not.
01:39It's actually been created mainly
01:41for a new specification that has not been finalized,
01:45or moved in to basically being finalized,
01:48which probably will be
01:49by the time you're watching this course.
01:50Hopefully it will be.
01:52In that specification, we have the capability
01:54of creating gradients.
01:57In this case, we theoretically don't have that approved yet,
02:00but most browsers have implemented it already.
02:02There is a chance that there might be changes,
02:04although not probable at this stage
02:06because it's moved already into the stage
02:08of almost being accepted.
02:11I want to show you that, and just for the context,
02:15the word transparent has been introduced already in CSS1,
02:17but it was reserved only for background images.
02:21In CSS3, transparent is just part of every color,
02:25it is a color, it is the color of no color at all,
02:27the see through color.
02:29So, lets see it in action.
02:30Let's go ahead in my script,
02:32and I'm gonna find a spot here in my nth-child, basically,
02:36where we have this array of colors you're going on
02:39of that specific color, and what I want to do is
02:41I want to create a transparency gradient.
02:44So, to do that, I'm going to go ahead here
02:45and I'm just going go ahead
02:46and start writing linear-gradient,
02:49and again, this might be changing,
02:52so don't take me word verbatim on this one,
02:54we'll create a separate title based on that specification
02:57once it's released and it's officially out there.
03:01The first property we're going to put your degrees
03:03is going to be between zero and 360,
03:05I'm just going to set it there at 90 degrees
03:07because I want it to go from left to right.
03:09Then I'm going to start putting in my colors.
03:10My first color is going to be this color,
03:13which has been already there.
03:15My second color is going to be transparent.
03:19I definitely didn't write that correctly,
03:21so let me do this again.
03:22Transparent, there we go, now it's right.
03:26I'm gonna close it, save it.
03:27If I go ahead and click on refresh,
03:29you'll see that now we're going to have
03:30a transparency going on to the color
03:32until it becomes invisible.
03:34I just want to clean it up a little bit.
03:36What I really want to do is I want to push the color
03:38to start transitioning a little bit later,
03:41so that the color will be nice and crisp.
03:44I'm going to go ahead and move it by putting here a space,
03:48and I'm going to write 25% to say
03:50I want the colors to start transitioning.
03:52Basically everything before that will remain the color
03:55that was already there.
03:57From the transparency, I'm going to say,
03:59hey, by the way, you go completely transparent
04:01by the time you get to 40% of the area.
04:04I'm going to go ahead and click on refresh,
04:07and now I'm gonna get a really nice transition, I think,
04:09that works really beautifully.
04:10I could have it go on a little bit further,
04:13or if I think that this space is not needed so much,
04:16I could go ahead and say that maybe 15 would work better,
04:20and maybe 45 here would work better,
04:22giving it a little bit more space to go
04:24so it doesn't get cut off so abruptly.
04:27Maybe that works for me better.
04:29That's basically how you work with transparent.
04:32It's now another color, and you could use it really
04:34in any place where a color could have been.
04:36You could just put the word transparent
04:37to basically say it's completely void of color, completely.
04:42By the way, it's completely different
04:44than if we were putting here color satches,
04:45for example, if we put here rgba,
04:49and we were putting here, for example,
04:50lets say I'm going to set it to be white,
04:52but as my last value, I'm going to put here a 0.
04:54Now, if I've done that, let me just make sure
04:56that my view is word wrapping,
04:58so that we can see the whole thing.
05:00This is a little bit different.
05:01If we look at the design,
05:03let me make it even more sharp, the difference.
05:05I'm going to set it to be 0, 0, 0, 0.
05:08Basically black, but invisible black.
05:11By setting to this invisible black,
05:13I want you to notice the difference,
05:14you're mainly right here.
05:16You'll notice that, maybe not as noticeable,
05:19you know what, I take that back, it's basically the same.
05:23What I was really trying to get to,
05:24and it really just depends on the rendering, I guess,
05:27is that if I would set it to black,
05:28then you would see this change in the color.
05:31I don't know of in any other scenario of combinations,
05:34asserting color might create that variety of color
05:39moving to that specific color.
05:41All I really wanted is for the color to go away.
05:43Transparent is the perfect answer
05:46from a logical point of view,
05:48even visually, it's hard for me to find
05:50this combination that would showcase why it would be better.
05:54In general, I really want to take it to transparent.
05:56I don't want to take it to black transparent.
05:58I don't want to take it to green transparent.
06:00I want to take it to transparent.
06:02You can see that there's a
06:04little bit more greenness in this,
06:06at least I think there is,
06:07obviously it's not a very big difference
06:09for us in this current context.
06:11In general, what I really want to do is I want to
06:13just set it to be transparent,
06:14and that's exactly why we use
06:16the keyword transparent, because we don't want to say,
06:18hey, it's the color of I don't know what.
06:19It stands for basically no color at all.
06:21Alright, so that's it, we are done with this lecture,
06:25we're done talking about transparent.
06:26We're getting very close to the end of this course.
06:29We're not ending it yet, so we're going to see you
06:32in the next lecture where we continue talking
06:33about another something that relates to colors.

Ready to Level Up Your Skills?

Join thousands of learners on 02GEEK and start your journey to becoming a coding expert today!

Enroll Now for Free!