📜 ⬆️ ⬇️

Positioning elements in HTML.

Sometimes there is a need to arrange html-elements in absolute coordinates. This can be done using styles.
For example:
<div style = "position: absolute; left: 100px; top: 20px"> <img> </ div>
In this case, the specified image will be located starting from the coordinates x = 100, y = 20.

And what if you need to arrange the elements relative to the center of the screen?
Here you can use nested divs. If two divs have a position style of absolute position in absolute, then the position of the nested one is measured from the position of the parent.
Example:
<div style = "position: absolute; left: 50%">
<div style = "position: absolute; left: -100px"> A </ div>
<div style = "position: absolute; left: 100px"> B </ div>
</ div>

In this example, the letters A and B will be located at a distance of 100px on both sides of the vertical line of the center of the page.

')

Source: https://habr.com/ru/post/9567/


All Articles