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

Relative positioning using CSS

PHPz
Release: 2023-08-27 15:13:02
forward
1267 people have browsed it

使用 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>
Copy after login

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

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template