How To Use Position Relative and Position Absolute Correctly

Using position in CSS is a big deal. It can be the difference between code that works OK in certain situations, and code that works beautifully every single time.

One really useful aspect to understand is using position: relative in conjunction with position: absolute.

Join us in our newest publication:

So lets say I want to fix a div to the right of another div. You could accomplish this a number of different ways, but the most useful would be doing the following:

HTML

<div class="outside"><div class="inside">

CSS

.ouside {
position: relative;
}
.inside {
position: absolute;
right: 0;
top: 0;
}

That would fix the .inside div to the right side of .outside. So no matter what happens to the .outside div, the .inside div will always be to the right and to the top:

So by setting any outside div as a position absolute, you can fix an inside div anywhere.

Important note: This is generally NOT supported by HTML emails.

Share and Enjoy !

0Shares
0 0