Adding dynamic Content before or after an element
It's time for us to meet a new type of selector. If you took our Absolute CSS course you already have met these selectors the: before a::after selectors. These selectors enable us to inject content before or after an element using the content property. By the end of this lesson, you will know how to add dynamically to your HTML content before or after the element using CSS2 content adding selectors.
properties: ::before, ::after, selector, css3, content
Video Transcript
00:00Over the last few lectures, we met a lot of different types of selectors, and we're moving on to a completely different type of selector group in this lecture.
00:09And in this one, we're actually going to talk about selectors that enable you to inject content into your HTML page.
00:15And yes, you heard me right. With the help of CSS, you can actually add content dynamically into your pages.
00:22This could become very, very useful if you have a digital book and want to add chapters or paragraphs or things that repeat themselves throughout.
00:29For example, if you're a news agency and you want to just inject in the middle of the article a text that would say, don't forget to register to our website,
00:38or a text that would repeat over throughout your website without cluttering your actual content,
00:43making it easy for you then down the line to go to that content and change it because it is in many ways a visual content.
00:50It's not really part of the document. It's more of a decoration that is added into the content.
00:56So by the end of this lecture, you're going to know how to add content before and after different elements.
01:01This was also covered if you followed us in our absolute CSS course, where we actually covered how to create a book titling with numeric system,
01:11which was not going to be covered in this lecture.
01:13And this one, we're going to take a different approach and learn a different thing.
01:16So if you haven't happened to have taken our CSS absolute CSS course, make sure to check that one out also before or after this lecture.
01:24So let's jump right into it.
01:26The next group of selectors we're going to take a look at are selectors that enable us to add content into our HTML page.
01:34Now, if you took our HTML, our CSS course, our absolute CSS course, then you already discovered the before and after selectors.
01:44They're very different than most other selectors that are out there.
01:48But we're going to spend a little bit of time with it, even if you've seen it already before.
01:51It will be a little bit of rehearsal.
01:53And for our students that just joined us into our CSS 3 course, it will be a really great addition because it's a very fabulous element.
02:01Now, I'm going to go ahead and create a very complicated example because it's already one that we've met before now in a previous course.
02:09Now, I want to go ahead and first define what are we trying to select and what I really want to do if I go back to my HTML,
02:16I want to make sure that every language that is listed will have the word new before it.
02:20Except for the ones that are disabled and have everything that is disabled right after it's coming soon.
02:27So I'm going to go ahead and build that. It is quite impressive.
02:30So I'm going to start off by defining that I want it only to happen to an input item.
02:34And I only want it to happen to input items that have a name of language.
02:39All right, so we're already weeding out the levels.
02:42And I only want items that are enabled.
02:45And again, because we don't want to change the actual checkbox itself or the radio box in this case,
02:50we want to go ahead and ask for that next to brother, the item that is right next to it.
02:57And I'm going to ask for the label right next to it.
02:59Not only do I want the label, I want to go ahead and say, by the way, label, and I'm going to put your two colons and then the word before.
03:06And that will enable me to basically say, hey, I want to go to the label and before that label just before or right in the beginning of that label,
03:14I want to go ahead and add here some content.
03:16And this kind of needs to be just plain text.
03:18And in this case, I'm going to write here new and I'm going to put your space.
03:22And if I say this and go back into my application, we'll see that now every single item will have the word new right before it.
03:29Very powerful, very advanced.
03:32So I'm going to go ahead here and just duplicate this item because I want to basically create the exact same thing.
03:37But I'm going to go ahead and do it for our disabled items.
03:42Excuse me.
03:43And instead of sending it to be before again, double colon.
03:46And I'm going to set after.
03:48Now, if you check out our absolute CSS and our absolute CSS course, we actually go through and show you how to create counters directly dynamically in CSS.
03:59So it's definitely worth checking out because that's been available for quite a while and saying that is very, very sweet and is not going to be covered in this group of lectures.
04:08As we're very focused on things that are incredibly CSS3 related.
04:13Besides selectors, which are so important that we felt we're going to go through every single selector, making sure that you have a really rounded look at selectors.
04:21So I'm going to go ahead here and for our content, I'm just going to set here coming soon.
04:26Soon.
04:30How about soon?
04:31Soon will be added.
04:35That's way better.
04:36And if I go ahead here and click on refresh, we'll see a really long soon will be added right inside of our element here that is disabled.
04:44And by the way, that gray is just so hard.
04:46I'm going to go ahead and just set it to be a much darker gray or even set it to be almost black.
04:51So I'm going to go ahead here and just set here one, one, one, one, one.
04:55Save that.
04:56Click on refresh because it's just just illegible at this stage.
05:00Let me.
05:01Oh, that was for enabled.
05:02So for disabled, I'm going to go ahead and it has to be gray, but it's just that gray just doesn't work because we're working with a blue monitor.
05:11So I'm going to go ahead here and just select the color here and just select here something that is dark, but not as dark as our other copy.
05:18So we'll make it easier to see that it's basically not really selected.
05:22I'm going to go ahead here and hopefully this color will be a little bit easier to read.
05:26Probably not.
05:27Oh, yeah.
05:28Here we go.
05:29I put here too many ampersands and there we go.
05:35All right.
05:36That works for me.
05:37Not as legible still, but at least it doesn't look harsh and bad.
05:41So there we go.
05:42Those were our before and after content adding selectors and we'll see you in the next lecture.
05:48We're still running through selectors.
05:50There's many more to come.
