positioning

Introduction

CSS can be used to position elements on a web page.
There are several ways to position elements, including:

Code - Static

<style>
  .box {
	background-color: lightblue;
	padding: 10px;
  }

  .box.static {
	position: static;
  }
</style>

Output

Code - Relative

<style>
  .box {
	background-color: lightblue;
	padding: 10px;
  }

  .box.relative {
	position: relative;
	top: 20px;
	left: -30px;
  }
</style>

Output

Code - Absolute

<style>
  .box {
	background-color: lightblue;
	padding: 10px;
  }

  .box.absolute {
	position: absolute;
	top: 20px;
	left: -30px;
  }
</style>

Output

Code - Fixed

<style>
  .box {
	background-color: lightblue;
	padding: 10px;
  }

  .box.fixed {
	position: fixed;
	right: 20px;
  }
</style>

Output