&"/> &">

Home >Web Front-end >CSS Tutorial >Relative positioning using CSS

Relative positioning using CSS

PHPz
PHPzforward
2023-08-27 15:13:021279browse

使用 CSS 进行相对定位

Relative positioning changes the position of an HTML element relative to its normal display position. So "left:20" adds 20 pixels to the element's LEFT position.

You can use the two values ​​top and left as well as the attribute for moving an HTML element to any position within the HTML document.

  • Move left - Use negative values ​​for left.
  • Move right -Use positive values ​​for left.
  • Move up -Use negative values ​​for the top.
  • Move down - Use positive values ​​for the top.

Example

You can try running the following code to achieve relative positioning -

<html>
   <head>
   </head>
      <body>
         <div style = "position:relative;left:80px;top:2px;background-color:yellow;">
            This div has relative positioning.
         </div>
      </body>
</html>

The above is the detailed content of Relative positioning using CSS. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete