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

Making things float

Now that our items talk with items that that surround them, it is time for us to learn how to help change the way elements lay out. In this first lecture of this topic we take a look at the way elements interact with the items that are right next to them. We will learn to use the clear and float commands.

Video Transcript

00:00Up until now, our focus was all about the element itself.
00:06We're taking a step away from the element
00:08and talking about the global rendering.
00:10That's gonna be the main topic of this chapter.
00:13And in our first lecture, this one,
00:16we're gonna talk about what is floating
00:18and how could you make things float
00:20and change the way their natural configuration works.
00:23So let's see it in action.
00:24Let's jump right into it.
00:26We're ready to take a step deeper
00:28into the world of mastering CSS.
00:31And now that we really know how to work with items directly
00:34and we know how to format them, we know how to color them,
00:37it's time for us also to talk about how to lay them out.
00:40And that's exactly what we are going to be doing
00:42in the following few lectures.
00:44Now, the first way of laying out is by default,
00:47an item automatically breaks a line whenever it's done.
00:51Or really, what's happening is that it's float
00:53is there is no float to it.
00:55And what I wanna do is I basically wanna tell it
00:58to float and enable by that other items to float around it.
01:02To do that, I'm gonna go into my styling rules
01:05right into the article item again,
01:07and I'm gonna go for the float command
01:10and I'm gonna tell it,
01:11hey, I want you to float to the left or to the right.
01:14And by setting my float to the left or to the right,
01:17I'm enabling those paragraphs to float in a direction.
01:20By the way, they affect everything else as well.
01:24So in this case, what I really wanna do
01:26is I probably wanna make my items float to the right
01:29and not to the, well, to the other direction
01:31to from the left to the right.
01:33So I'll set it to float from the left
01:35and I'll just leave your comment
01:36just so you could go ahead there
01:38and peek at the different various options
01:40that you could set to our items.
01:42And I'm gonna set, just put that right there,
01:46where inherit would be the default,
01:48where none would be really the real default, either or,
01:52where or it's gonna inherit the properties from
01:54if there's a float going on and something above it
01:56or none, which is the actual default.
01:59Now, left or in the right,
02:00we already know how to work with them
02:02and I wanna talk about one more thing
02:03so we could see that right now,
02:04now that we set these floats
02:06and we have our items floating,
02:07we're creating a very unclear message
02:10for our next item that doesn't really know
02:13how it should be aligned.
02:14And we wanna help it out by basically telling it,
02:17by the way, you wanna clear line
02:19to start from a clear line,
02:20don't relate to these elements that are here.
02:24To do that, I'm gonna go into the actual footer itself,
02:27into the CSS of the footer
02:29and add another attribute that is called clear.
02:32And the clear accepts the exact same type of parameters,
02:37it only has one more that is not inside of the regular one,
02:43which is the option to have both sides clear.
02:48And really what clear does is it makes sure
02:49that on both edges, if we set it to be on both edges,
02:52it makes sure that we have a clear line,
02:54there's nothing before or after this item.
02:57So I'm gonna go ahead there
02:58and just set my clear to be both.
03:01And if I go ahead and save my item and refresh,
03:04we'll see that now our footer will be back
03:06underneath where we want it to be.
03:09And that's one very, very useful way to align items
03:12such as, for example, if you wanna position
03:13a few images one after each other
03:16or you wanna position different elements,
03:18such as in this case, where we put two paragraphs,
03:20one next to each other instead of one under each other.
03:23And that covers this topic.
03:25We're not done talking about layouts
03:27because we're gonna continue talking about that
03:29in the following few lectures.

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!