Left, right, top and bottom

In this article we are going to learn about left, right, top and bottom properties, in css, how to position elements in html.

Left, right, top and bottom

These are Cascading Style Sheet properties used to position html elements, how far from the left, right, top or bottom an element should be placed.


Left

This is a css property used to control how far from the left an element should be placed in html.

Let us add an image element with 10px left property applied, copy and paste below code.

<!DOCTYPE html>

<head>

<style>

.left-example {

position: relative;

left: 10px;

background: orange;

}

<style/>

</head>

<body>

<img class="left-example" src="images/icon.png" alt="scienceinlesotho icon">

</body>

</html>


So, we should have the following results.

scienceinlesotho icon

Right

This is a css property used to control how far from the right an element should be placed in html.

Let us add an image element with 5% right property applied, copy and paste below code.

<!DOCTYPE html>

<head>

<style>

.right-example {

position: relative;

float: right;

right: 5%;

background: orange;

}

<style/>

</head>

<body>

<img class="right-example" src="images/icon.png" alt="scienceinlesotho icon">

</body>

</html>


So, we should have the following results.

scienceinlesotho icon

Top

This is a css property used to control how far from the top an element should be placed in html.

Let us add an image element with 1% top property applied, copy and paste below code.

<!DOCTYPE html>

<head>

<style>

.top-example {

position: relative;

top: 1%;

background: orange;

}

<style/>

</head>

<body>

<img class="top-example" src="images/icon.png" alt="scienceinlesotho icon">

</body>

</html>


So, we should have the following results.

scienceinlesotho icon

Bottom

This is a css property used to control how far from the bottom an element should be placed in html.

Let us add an image element with -0.5% bottom property applied, copy and paste below code.

<!DOCTYPE html>

<head>

<style>

.bottom-example {

position: relative;

bottom: -0.5%;

background: orange;

}

<style/>

</head>

<body>

<img class="bottom-example" src="images/icon.png" alt="scienceinlesotho icon">

</body>

</html>


So, we should have the following results.

scienceinlesotho icon

Conclusion

In this article we learnt about left, right, top and bottom properties, in css with examples, how to position elements in html.