Let's say I have a simple table on my site
<table class="table table-striped table-bordered">
and I want to move it
20px from the top. Should i use margins
or better use absolute positioning
Which way is a better practice?
To answer your question, let's consider that there are multiple tables similar to the one you have one after the other.
In case of using
position:absolute style along with
top wouldn't fulfill the task. Because in that case you have to calculate manually how much top px you want for each table, whereas if you use
margin-top style rule. It will work perfectly with ease without manual calculation. Hence both style rules are different to each other and are used for different reasons. I hope you understand.
Use a margin if your intent is simply to add whitespace between the table and preceding element. Absolutely positioning the element may have the same effect but also has other (likely) undesirable side effects: