Today I was learning 2 concepts in CSS, one is CSS positioning (static, relative, absolute, fixed) and the other is CSS Margin, which define the space between element.
Let's say I wanted to move an element, which is the best way of doing it?Since both concept seems to be able to do the same thing. An example might be as follow:
The Code(CSS Positioning):
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Haha</title>
<style type="text/css">
//Using CSS positioning
h2{position:relative;top:-80px}
</style>
</head>
<body>
<h1>hahahaha</h1>
<h2>hehehehe</h2>
</body>
</html>
The Code(CSS Margin):
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Haha</title>
<style type="text/css">
//Using CSS Margin
h2{margin-top:-80px}
</style>
</head>
<body>
<h1>hahahaha</h1>
<h2>hehehehe</h2>
</body>
</html>
The Question:
1.)As you can see the 2 codes above did the same thing by moving the second header to the top of the first header. So I just wonder which method is actually the correct way in arranging element?