Using Relative and Absolute Positioning – CSS Basics

Now I want to show you how you would use relative and absolute positioning together. Let’s start with absolutely positioning one of these elements We’ll start with three div tags, three div containers rather, that are all stacked on top of each other. I haven’t assigned these divs any other properties except for the background colors as you can see here. The first thing we’ll do is absolutely position div #one.
So we’ll go to #one and I’ll add the position property and it will be absolute and now i’m going to add the right:0 property to it
it anos a zero a sewer lines all way to the right an element of the
way it’s as we know ’cause ought by default is constriction
at the entire length of the screen and i’ll give it three hundred pixel
width okay so let’s look at the result of her
hair now we see that before one was on the
was on top since i act right here since i absolutely position that they
went out of the normal documents flow acquisition it to the right through
controls so on and move it when i move the browser like this one
always hits here elicits to the right the reason why that is is we happened to
find anything that one is going to stick to the right relatives too so that means that our property is going
to be are right zero is going to be right to the browser from completely
zero pixels from the right by the browser
crowd but here’s a miniature i’m going to put one two and three inside of a container
and i’m going to mean that did container well you’ve probably guessed it container so here we go actually i would have done the same head
of time and here’s my container kids right over here and basically now i need
to meet the clarinet my style over here container and give them going to do to yet then went
to container and then define a with foreign so we see exactly what we’re doing okay and position and when it make it relative now the interesting thing is is that
this relative positioning is in perfect the container to actually get affected
things we’ve seen the container because now we
have one absolutely positioned to the right three hundred pixelime to the right zero
pixels and that was to the browser problem but now it’s going to be to the container so let’s see what that ends up looking
like you see how officer now this thing is to
the right scale zero pixels to the right but this time to the right
of this invisible container actually what i’ll do is kissling you see exactly
what i’m talking about if i five put some padding contest ended about ten pixels and all set a background colors welts
regency so we could see the other borders of how this is working okay there we go and can even squeeze it
even more so here’s our container with that witty patting of and pixels but week absolutely positioned one
stephenie squeeze this to the side what happened is we absolutely
positioned one zero pixels to the right and there it is so what do you think would happen if i took
out relative positioning from container here’s my guess if ivy took out relative positioning from the container one would go zero pixels too the chrome to the browser problem
because since nothing else is defined it defaults relative positioning is to the browser
chrome let’s see if i’m right uh…


Add a Comment

Your email address will not be published. Required fields are marked *