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

Modifying the HTML and CSS

Before we continue and build our canvas API example we want to align the canvas element to sit on top of our HTML frame.

After creating the canvas element we will need to position our canvas in the right area of our screen to do that we will use some CSS tricks to position our canvas exactly where we want it to be placed. Although we are not actively learning CSS in this title the basics of CSS are easy to follow.

We started our canvas tutorial using a pre-built template HTML file. The first thing we will want to do is figure out where to place our HTML5 canvas information followed by filling the canvas background color so we can find it using the canvas API.

After creating the canvas element we will need to position our canvas in the right area of our screen. To possion elements we will use CSS. We are assuming you have a background in working with CSS if you do not you may follow us by steps - don't worry it will not effect your learning of Canvas. With that said we do encourage you to learn the basics of CSS (you don't need to be a CSS pro). Although we are not actively learning CSS in this title the basics of CSS are easy to follow.

Canvas Tutorial

In this video we will solve all the video positioning issues. To make this happen we will be adding some CSS. We will add a style for our canvas. Before we do that we will change the containing layer to be a relative layer enabling us to change the definition of our internal canvas element to be absolute making it really easy to snap it into position. All we have left is to move our element in absolute coordinates using top and left CSS properties.

Video Transcript

00:00So to make that happen, what we're going to do is we're going to have to change some CSS.
00:04So we're going to go back into the CSS. And in our CSS, we're going to, I'm just going to add
00:09here another style. I'm not going to create a new file for this or mix into the file that already
00:15exists. And let's figure out, okay, so for our style, first of all, we have to do two things.
00:20One is we're going to have to go to our top div and set it to be relative for its position to be
00:27relative. All right, so I'm going to go to my top, my top selector, and I'm going to set its position
00:35to be relative. And that's going to enable me to set the internal position of our my canvas
00:47to be absolute. By making it absolute, now I could force it and set it with specific pixels
00:54and really pinpoint where I want it to be. So my canvas, I'm going to set it to be left 15 pixels.
01:02Because right now if we're looking at you'll see that we want to push it a bit to
01:06and our position our 00 is going to be more or less like right here in the beginning of our header,
01:12which is up right here. So I'm going to basically want I want to push it 15 pixels, which is what
01:18we are doing right now. And if I actually refresh it, we'll see that it's going to be move, it will
01:24move, you know, let's, oh, we actually didn't complete right, we first have to set its position
01:31to be absolute. And now our 15 pixels will be reflected because our our position is absolute.
01:42So now the last thing, well, not exactly last, because right now you see that our element is
01:45coming right under our logo. And that makes sense. But we actually wanted to go all the way down to
01:52the specific I hate these airplanes. We wanted to go into the specific pixel that we need. So again,
01:58we're going to set it to be top. And we're going to set exactly how far from the top we want it to
02:03be. And in our case, we want it to be 124 pixels from the top. And again, if we refresh it again,
02:09we'll see that our element goes exactly in the top corner. And if we resize our element,
02:15we'll see that it stays and there's no issues. So that's good. And we're ready to continue drawing
02:22with our canvas. Only thing is that we want to probably push our footer up a bit. So for it to
02:27do that, what we'll do is we'll take advantage of our header, and we'll just approach our header
02:33itself and just kind of like get rid of a bit of the margin. So I'm going to pick my header.
02:40And for my header, this time around, I'm going to change my margin,
02:43bottom. And I'm going to set it to be minus five px, five pixels. So like that it that should solve
02:51it. But it didn't. So let's see if I did hear something wrong. I must have typed it incorrectly.
02:57Oh, header, I was missing there and er. Perfect. Alright, so now we got all of our HTML done.
03:07And it's time for us to really dig in.

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!