Register to get access to free programming courses with interactive exercises

Relative positioning CSS: Positioning

Positioning is a large module in CSS and allows you to describe how an element within an HTML document can be placed outside the normal document flow. As discussed in the last lesson, normal document flow is where all elements are rendered in the sequence in which they are entered within the HTML document.

One commonly used positioning type is relative positioning. The main question you might have from the very beginning is: "What will the element be positioned relative to?" The answer is simple enough, relative to its original position. The item stays in the document flow, and no other elements try to take its place.

Relative positioning is often used for visual effects, such as creating a shadow with a second block, or for a small animation when the mouse pointer hovers over an element.

When the mouse is moved over an element (you can use the .animate-hover:hover selector for this), we used the CSS rule position: relative, which means we're applying relative positioning to the element. You can control the positioning of an element with the position property by using four CSS properties:

  • top
  • right
  • bottom
  • left

positioning in CSS

Each of these properties takes a value by which the element will be moved. These values do not have to be positive, the properties also take negative values. Try changing the values in the example above and see how the different values of the top, right, bottom, and left properties work.

relative positioning


Are there any more questions? Ask them in the Discussion section.

The Hexlet support team or other students will answer you.

For full access to the course you need a professional subscription.

A professional subscription will give you full access to all Hexlet courses, projects and lifetime access to the theory of lessons learned. You can cancel your subscription at any time.

Get access
130
courses
1000
exercises
2000+
hours of theory
3200
tests

Sign up

Programming courses for beginners and experienced developers. Start training for free

  • 130 courses, 2000+ hours of theory
  • 1000 practical tasks in a browser
  • 360 000 students
By sending this form, you agree to our Personal Policy and Service Conditions

Our graduates work in companies:

Bookmate
Health Samurai
Dualboot
ABBYY
Suggested learning programs
profession
Development of front-end components for web applications
10 months
from scratch
Start at any time
profession
Layout with the latest CSS standards
5 months
from scratch
under development
Start at any time

Use Hexlet to the fullest extent!

  • Ask questions about the lesson
  • Test your knowledge in quizzes
  • Practice in your browser
  • Track your progress

Sign up or sign in

By sending this form, you agree to our Personal Policy and Service Conditions
Toto Image

Ask questions if you want to discuss a theory or an exercise. Hexlet Support Team and experienced community members can help find answers and solve a problem.