Defining opacity levels
In the last few lectures we played around with color by defining backgrounds and foregrounds of color. At this stage we are ready to take a look at controlling the opacity of elements.
Video Transcript
00:00Welcome back to a new chapter.
00:02In the last chapter, we talked about backgrounds
00:04and we spent a lot of time talking about colors
00:07and color theory.
00:08In this chapter, we move on continuing
00:10to manipulate elements as we start off
00:13with manipulating its opacity.
00:16So let's jump into it and see, how does that work?
00:18How do we change the opacity of elements?
00:21It's time for us to steer our attention
00:24and back into our CSS, I wanna talk about visibility.
00:28In previous examples, we saw how we control our alpha
00:32using an RGBA where we could control an alpha
00:36and set its visibility in that way to be zero.
00:40But really, we never really wanna use RGBA
00:43to set a visibility of no visibility.
00:45And the reason is because that is still being rendered.
00:49And rendering of this type of kind
00:51is really intensive on a processor.
00:54Like we were saying, also alpha channels
00:56are intensive for a processor.
00:59I wanna go ahead and show you an example using the article.
01:02I wanna go ahead and make that article invisible.
01:06To do that, I'm gonna go into the article itself.
01:08I'm gonna put here a comma here.
01:10Notice how my display here on my alpha channel
01:13is of the background, but I'm gonna go ahead
01:15and I'm just gonna break a line here
01:17and push everything up a little bit.
01:19So let me add here a few more break lines
01:21so it'll be in a good position on the screen.
01:23And I'll put the value opacity
01:26and set that opacity to a value between zero or one.
01:29Now, the opacity value contrary to the alpha channel
01:34that only controls the background
01:36will control the whole instance.
01:38So for example, if I set the opacity to be 0.5
01:41and I go back into my application and click on refresh,
01:44we'll see that everything including descendants,
01:47which descendants are items inside of that item
01:50will now be faded out in a 50% opacity.
01:54Again, if I wanted to, I could have set that opacity
01:57to be zero as well.
01:59The only problem with configuring
02:00and setting my opacity to be zero
02:02is that it is processor intensive because,
02:06excuse me, the browser itself
02:08has to process that element and display it.
02:12Now, actually display it as not displayed.
02:15Now, contrary to opacity, and I'm gonna go ahead here
02:18and just set here maybe an opacity of 0.8
02:21just so it's still there, that property,
02:23so you could look at it.
02:24And I'm just gonna go ahead and also make sure
02:26that you have here a comment
02:28so you know what the ranges are,
02:30and the ranges are between zero and one.
02:33All right, so let's move on to the next property
02:35that I wanna talk about
02:36that relates to color and visibility.
02:39And that is the visibility property.
02:43Now, the visibility property by default
02:45has the value of visible, which as the name implies
02:49means it is currently visible.
02:52Sub, sub, well, underneath that, other options are hidden.
02:57Now, the hidden option basically
02:59hides our element completely.
03:01So it doesn't really matter
03:02if we have an opacity of 0.8.
03:04Our element is invisible.
03:07But the space itself that controls that element,
03:10the space that is registered for that element
03:12is still in position, so nothing here is moved.
03:15The item is here, it's just not being rendered at all.
03:19It's a little bit easier on the processor
03:20because there is no rendering.
03:22The only thing the processor needs to do
03:24is save the space there for that element.
03:26Now, the hidden property in its default,
03:31well, not only default,
03:32by default it will make everything inside
03:34all internal elements inside of it
03:37to be invisible as well.
03:39But that's only a default which you can override.
03:41For example, if I wanted to override the questions item
03:45and say, hey, for the questions itself,
03:47which is a sub-item, it's a child of this item,
03:50so I'm gonna go ahead here and just break a few lines,
03:53I actually wanna have a visibility that is visible.
03:57So I'm gonna go ahead here
03:58and set a visibility of visible.
04:00Now, notice the default that was a visible
04:03that was there originally is not that default anymore
04:06because the question automatically inherited
04:09the article's visibility, which basically made it hidden.
04:12By setting it to be visible,
04:14now the article itself will be visible
04:16even though that wrapper around is not.
04:20And notice how all the children of that property
04:23are now getting that configuration, that visibility.
04:26Now, I'm gonna go ahead here in the comments itself again
04:29and I'm just gonna add the different various options
04:32that you could put in for visibility.
04:34And again, we have here our visibility
04:37that is the default visibility
04:39unless there is some inheritance going on,
04:41unless a child is inheriting a feature that is different
04:44like we saw in our article.
04:45No matter where the position is,
04:47if the question is before or after, it doesn't matter
04:49because this is a descendant,
04:50which its laws are applied after the laws of the article
04:54because it's closer down in the chain of line
04:57to the item itself.
04:59Now, hidden we've saw,
05:00collapse we're not gonna see in this title,
05:02we're gonna see it in a future title,
05:04but that relates mainly to working with tables.
05:07And as we're not working with tables,
05:08right now we're gonna ignore it in general.
05:11I wanna move on to one more topic.
05:13And to do that, I'm gonna go ahead
05:15and just add this whole item here
05:17into, to be commented out
05:21because I wanna talk about another way
05:23to control visibility.
05:25Now, this new other way of controlling visibility,
05:28and I'm gonna go ahead here,
05:29oh, that was actually fine,
05:32but I'm gonna go ahead here
05:33and just dim out our visibility,
05:36set it into the comments.
05:37I'm gonna go into the property that's called display,
05:40and there's a lot of things
05:41that we could do with the display.
05:43We're not gonna talk about all of them now,
05:45but throughout our course we're gonna meet a lot of them.
05:48The first thing we're gonna see in it is the none.
05:52Now, the none contrary to visibility,
05:54although will look like it does the same thing maybe
05:57in the first second,
05:58does something completely different.
05:59And notice the difference.
06:01The difference is, is when I set the display to none,
06:03it actually is not accounted at all,
06:06which means that items that are flushed after it
06:09are gonna be flushed immediately,
06:10removing that space of that item.
06:13Another difference between that item
06:15is that children cannot override.
06:18So if I go inside of my display here
06:20and I try to enter something else inside of the question,
06:23it would not adhere to it because the parent,
06:26if the parent has set it to be none,
06:28then all the children below it are automatically none.
06:31They cannot override it.
06:33Contrary to visibility hidden,
06:35where children can override, all right?
06:38And the logic is very simple
06:39because if the whole element is gone,
06:41then it really doesn't matter
06:43if internal items are visible
06:44because that whole node is just not visible.
06:47All right, so that covers that item.
06:49And that's really our conversation
06:51about opacity in general
06:53and how to make something visible or not visible
06:56and the differences between hidden visibility
07:00versus the display none.
