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

Manipulating inner content with inner content selectors

In the last lecture we were introduced for the first time to selectors that enable us to change content or talk to an area within our content. In this lecture we continue and explore two more selectors that enable us to select part of the content in our page. Both selectors were added into CSS1 and enable us to change the style of the first letter in an element or the full line. By the end of this lesson, you will know how to work with the::first-letter and ::first-line CSS1 selectors.

properties:css1, ::first-letter, ::first-line, selector

Video Transcript

00:00In the last lecture, we met CSS selectors that enabled us to inject content into our page.
00:06And really, we're approaching a new type of selectors.
00:10And in this selector, we're going to go back in time, really, because we're going back to CSS1 selectors.
00:16And the selectors we're going to meet in this lecture are selectors that enable us to actually modify the content within that already exists.
00:23And by then, this lecture, you will know how to change the layout of the first character or the first line inside of an element.
00:33Now, this becomes really, really useful again in books if you want to, for example, create where the first character is much larger and the content is flowing right next to that content,
00:41which is exactly what we're going to do in this lecture.
00:44So let's jump right into it.
00:46We're about to talk now about selectors that have been around since CSS1.
00:51So this is not as exciting, although I really love it and you don't see it as often on the web and I don't know why.
00:59So I'm going to go ahead and just jump right into it there from the same type of rules that we met in our last session, their content driven.
01:06And as such, they're changing the content and their structure is a little bit different than regular items.
01:12Now, I'm going to start off by saying, what do I want?
01:14I want to go to every paragraph and I'm going to put that double colon like we had with the before and after.
01:20And now I'm going to say first line.
01:24Now, what's that that's going to do is going to help me control the first line of my paragraph.
01:29So, for example, if I wanted to, I could have set my font size to be how about we set it to be 50 percent larger than its current size.
01:38So I'm going to go ahead there and save that its default size, its current configuration.
01:42I'm going to double up its size.
01:43And if I go ahead and refresh my browser, we'll see now every single paragraph in our application.
01:49Its first line is going to be doubled in size.
01:52I want to continue and also showcase the next item.
01:56They're both very simple, so I'm not going to talk about them for too long.
01:59I'm going to go ahead and just copy this paragraph first line.
02:03And instead of setting it to be first line, I'm going to go ahead and set it to be first letter again.
02:08CSS1, quite amazing that this existed in CSS1.
02:12And for the first letter, I'm just going to go ahead and make it really large.
02:15I'm also going to set it to float because if I don't, if I just set that first letter to be large,
02:21let me just show that if I just set that item to be larger,
02:24then we'll have a really large first character and our copy would continue flowing naturally.
02:30But what I really want to happen is for this item to float so the content will scroll around it.
02:36To make that happen, I'm going to go ahead into my code here and let me make it just four.
02:40That seemed way too big.
02:42And I'll set my item to float to the left.
02:44I'm going to also give it a margin just to make sure that it's nice and pretty.
02:48I'll set there 15 pixels.
02:49I'm going to go ahead and click on refresh.
02:52And notice how I used here absolute positioning of 15 pixels.
02:56That might be wrong of me.
02:57I might, it might be smarter of me if I wanted to keep my application very dynamic,
03:02is to literally set it based in EMs as well.
03:05So that's how I start with one E dot one E M.
03:08If I go ahead and refresh that, if I'm happy with the results of that, then I could keep that.
03:12Just bear in mind that if I take this one E M and I put it after I resize my font,
03:19notice the difference or lack of difference.
03:21Let's see.
03:22Once I set it after, notice that the item is rendered this the same way,
03:27but it is very hard to know.
03:30So what is it?
03:30What is zero to one of the original size is a zero dot one of the new size.
03:35Best way to define that is just put the value of one there.
03:38And if we put the value of one there, and if we see the spacing just more or less natural,
03:42then we know we're fine.
03:43But in this case, we're seeing that that one that E M is based on that new font size.
03:49If I just jump it right up here, even if it's sitting, if the margin is sitting above,
03:54that does not change the fact that it's defined based on the actual size of this element.
03:59So make sure when you're defining your size here to make sure that you're really using small sizes.
04:04And you could go also to the really small fractions.
04:07And that's completely fine.
04:08Finding that right perfect value and ratio to your font size that you're using.
04:14If you don't want too much spacing, but in my case, that would probably be too much.
04:18So I'll go ahead here and set it to one.
04:19But also one more thing, you know, in these episodes,
04:22always you could always grab the element, inspect it, find it,
04:25find the spacing, find that margin, and then play around with the value.
04:29Is that two good?
04:30Is that three good?
04:32Is that two?
04:33Is that maybe one five?
04:35And I'm happy with one five.
04:36So then I'll go ahead and just set it to be one five.
04:40All right.
04:40So that's it about our about content selectors in general,
04:44where in the last lecture, we started the before and after content adding selectors,
04:49which were new to CSS two.
04:51And in this lecture, we've seen the CSS one inner content selectors
04:55that enabled us to add, manipulate our content in our first line
04:59or our first letter of our paragraph.
05:03So that's it.
05:04We're done with this lecture.
05:05We're not done with selectors.
05:06So we'll see you in the next lecture as we continue exploring CSS selectors.

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!