How to align A better HTML text

Asked

Viewed 195 times

-3

Good want to Align a text or an image anywhere on the screen for example:

     Um texto aqui outro                           



 outro aqui                                                              e aqui  
  • Depends on the structure of your HTML. You can use text-align, margin etc in CSS, for example.

1 answer

0

To position elements arbitrarily anywhere on the screen you can use the style position with fixed (position in relation to the body). The latter, the element will be fixed on the screen, that is, if there is scroll, he will not move.

Beyond the position, you use two more styles, the top (distance from the top) and the left (distance from left).

There is also the position: absolute which does not make the element fixed, but it will position itself within the parent element if it has defined some position (absolute, relative or fixed). If not, it will take as a basis the body or, if there is, the first element above in the tree that has one of the above styles.

Example with fixed:

span{
   position: fixed;
}
<span style="top: 0; left: 50px;">Um texto aqui outro</span>
<span style="top: 100px; left: 20px;">outro aqui</span>
<span style="top: 100px; left: 500px;">e aqui</span>

Example with absolute:

span{
   position: absolute;
}
<span style="top: 0; left: 50px;">Um texto aqui outro</span>
<span style="top: 100px; left: 20px;">outro aqui</span>
<span style="top: 100px; left: 500px;">e aqui</span>

As stated, the absolute does not make the element fixed and positions itself inside the parent element. In the above example, since the elements are not within a specific element, they are positioned based on the body.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.