Hi guys. What do you usually use on positioning HTML elements? Margins or CSS positioning (absolute, relative, etc.)? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Hi guys. What do you usually use on positioning HTML elements? Margins or CSS positioning (absolute, relative, etc.)?

10th Nov 2018, 5:11 AM
Christian Besmanos
Christian Besmanos - avatar
4 Answers
+ 1
Depends on context...For simple spacing between correlated elements, i use margin but for layout i use positioning
10th Nov 2018, 5:54 AM
KrOW
KrOW - avatar
+ 1
I concur with KrOW. Use positioning for layout of larger components (e. g. nav vs main) and margins for elements that should flow together within these larger components (e. g. to manage space between the border of a button / anchor / image and another border). Margins are more straightforward when they work. (Sometimes they collapse.) Positioning is trickier, but getting it to work right can mean longer code (since it can't be done in shorthand like margin can). I think you should continue to use each where appropriate. Desiring clean code does you service, but it may be going overboard in this case to use only one or the other.
10th Nov 2018, 9:07 AM
Janningā­
Janningā­ - avatar
+ 1
Thank you for your answers, I appreciate it. So now on I'll keep using both of them. Again thanks!
10th Nov 2018, 11:54 AM
Christian Besmanos
Christian Besmanos - avatar
0
I also do the same actually, I'm just wondering if there is a recommended way of doing it. ( Sometimes it's confusing so I want to use only one of them. To make my code uniform and look clean)
10th Nov 2018, 5:58 AM
Christian Besmanos
Christian Besmanos - avatar