Adding content before and after elements dynamicall
Sometimes you will have a batch of copy you want to put into HTML pages. It would be a horrible waste of time to copy/paste this content over and over %u2013However, CSS enables us to dynamically define repetitive content as a part of the CSS rules. By the end of this lesson, you will know how to add content before and after HTML elements.
Video Transcript
00:00really advanced, really cool.
00:02What happens if you want to add content dynamically
00:05through CSS and that would happen in situations
00:08where you want to add the same content always
00:10if it's throughout your application
00:13or maybe directly in a title such as
00:16maybe you want to put there something
00:18something that repeats itself like he said, she said
00:21and you don't want to need to write it 100 times.
00:24For example, there's a conversation between two people
00:26and you want to refer to he, she, he, she 100 times
00:30but you don't want to type it, beautiful.
00:33That's what we're going to look at in this lecture.
00:35It is incredibly powerful, incredibly cool
00:37and it connects to the next topic
00:39that we're going to talk about in the next lecture
00:41but let's jump right into this one
00:43and we're going to continue something really amazing
00:45in the next lecture.
00:46And between the lectures, I tweaked our HTML a little bit
00:49by adding a few more H2 titles.
00:52Now, I want to talk about a few things
00:54and we're going to use that in a few lectures for now.
00:58What I want to do is I want to show you
00:59how could you add content to a paragraph
01:02or really any HTML element, any textual data
01:06to any element dynamically through CSS
01:09and this could be very useful
01:10if you want to have some sort of marketing message
01:12or add some something that repeats itself into elements.
01:16Now, in this case, what I want to do
01:17is I want to go to paragraphs
01:19that are inside of our article
01:21and I want to add to it basically something like he said
01:23or something of that nature.
01:25So I'm going to go ahead and find our articles
01:27which is inside article P
01:30and I'm just going to copy that path
01:32because what I want to do is I don't want to go into it.
01:34What I want to do is I want to take that and say
01:36I'm going to put your colon and I'm going to say before.
01:39Now, before literally enables me to inject something
01:42right before our paragraph
01:44and in this case, I could go ahead and add some content
01:47using the content command
01:49and literally just put here some string.
01:51So in this case, I'll put a string value
01:53and I'll write inside he said that
01:59and I'll just save it, go into my application,
02:03click on refresh and notice now
02:04that all my paragraphs that adhere to this rule
02:07will start with he said that, three dots.
02:10Let's continue.
02:11So beyond just as much as we could have created
02:14a before using this interesting new colon
02:17which we're going to meet a few times
02:18which they relate to actions or directives,
02:20things that are not necessarily directly on the stage
02:23but it's more, in many ways,
02:24it's kind of like the properties of that element
02:27saying we want to do it before
02:29or in this case, we want to do it after.
02:32So I could go ahead and have year and after
02:36and I could end it with that is what he said
02:45and I could go ahead and save it
02:49and refresh my application again
02:51and this time around, we'll see that that is what he said
02:53and we'll also find that if we scroll all the way
02:56to the end of our element here as well.
02:59So that is the before and after
03:00and before we wrap this, I want to show you
03:02how could you leverage this to modify quotes as well.
03:06Now, in general, what I could do
03:08is I could decide that for paragraphs,
03:10I want to manually enforce for these paragraphs
03:13a quoting system.
03:14To do that, I could go ahead here
03:16and I'm just going to comment this value out
03:19for a second here and instead of that,
03:23I'm going to write open quote.
03:28And I'm going to go ahead and do the exact same thing
03:30only this time around, I'll set it to be close quote
03:34for our after and I'll go ahead and save that
03:41and I'll go ahead and click on refresh
03:44and we'll see that we have here that double quotation
03:46in the beginning and ending.
03:48Now, if we wanted to create a not an opening quote
03:52or not a closing quote,
03:53that really just means the one quote.
03:55So in that case, I could set it to be no close,
03:59no open quote, no close quote.
04:03And in that case, I could then define it and set it
04:06so you could literally define it
04:08that whatever way you want,
04:11but really in this case,
04:11I don't really want to have no opener.
04:14I really want to have an open element.
04:16I really want to have a close,
04:17but what I really want is to have a single quote,
04:20for example, in this case.
04:22Now, one way to do that is I could override the defaults
04:25globally for the whole application
04:27or specifically for these paragraphs.
04:29So I could say for these specific paragraphs,
04:31again, going into the paragraph
04:34and I could say, okay, now first,
04:36I want to give it a language directive.
04:38So I type in the words lang and then en for English
04:41because we're in English
04:42and then I could define how quotes look like.
04:45So I could just say, hey, by the way,
04:47a quote looks like a single item
04:49and it closes with a single item as well.
04:53And that's all I really had to do
04:55to change the way quotes work in English.
04:58First, the specific paragraphs.
05:00And if I go ahead and click that and click on refresh,
05:02then I would have that single quote.
05:05Now really an essence in my,
05:07what I would probably do is just manually put in here
05:09the strings that we would want
05:11and control that if I wanted that level of control.
05:14And that's it.
05:15This covers basically the essence of before,
05:17after working with these directives
05:20that are beyond just like approaching an item directly,
05:22but saying, hey, I want to do something
05:24that's connected to a language.
05:25I want to do something that's connected
05:26to before this item, after this item.
05:28There are many more other properties
05:30that we did not explore in this title,
05:32but we're going to see a couple more
05:33before we finish up this title moving on to the next one.
05:36So we'll see in the next lecture
05:37where we continue looking at different interesting,
05:40more advanced things that you could do in CSS.
