CSS Classification Tutorial

How to position an element with the position property and a relative value with CSS

The code below shows you how to position an element with the position property and a relative value with CSS.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title>Web Development Tutorials.com</title>

<style type="text/css">
p.leftpositioning
{
position:relative;
left:-20px;
}
p.rightpositioning
{
position:relative;
left:40px;
}

</style>

</head>
<body>
<p>
This is a paragraph. This is a paragraph.
</p>
<p class="leftpositioning">
This is a paragraph with a relative position of "left: -20px".
</p>
<p class="rightpositioning">
This is a paragraph with a relative position of "right: 40px".
</p>
<p>
This is a paragraph. This is a paragraph.
</p>
</body>
</html>

The code above creates the following web page:
how to position an element with a relative value with CSS

Use the text editor below to practice what you have learned.