0
Hi guys. What do you usually use on positioning HTML elements? Margins or CSS positioning (absolute, relative, etc.)?
4 Antworten
+ 1
Depends on context...For simple spacing between correlated elements, i use margin but for layout i use positioning
+ 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.
+ 1
Thank you for your answers, I appreciate it. So now on I'll keep using both of them. Again thanks!
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)