Home  >  Article  >  Web Front-end  >  How to use css for positioning? Detailed explanation of CSS layout and positioning

How to use css for positioning? Detailed explanation of CSS layout and positioning

云罗郡主
云罗郡主Original
2018-10-31 17:29:172768browse

How to use CSS for positioning? CSS can help you position HTML elements. You can place any HTML element anywhere you like. You can specify whether you want the element to be positioned relative to its natural position on the page, or based on its parent element definition. Let’s explain CSS layout and positioning below.

How to use css for positioning? Detailed explanation of CSS layout and positioning

1: Relative positioning

Relative positioning changes the position of the HTML element relative to its normal display position. left:20 adds 20 pixels to the element's LEFT position. [Recommended reading: Detailed explanation of relative positioning, absolute positioning and fixed positioning]

You can use the top and left values ​​​​and the position attribute to move HTML elements to HTML anywhere in the document.

Move left - Use negative values ​​for the left side.

Move right - use positive values ​​on the left.

Move up - Use the top negative value.

Move down - use positive values ​​for top.

Note - You can also use the bottom or right values ​​in the same way as top and left.

2: Absolute positioning

position: The absolute element is located at the specified coordinates relative to the upper left corner of the screen.

You can use the top and left values ​​​​and the position attribute to move an HTML element to any position in the HTML document.

Move left - Use negative values ​​for the left side.

Move right - use positive values ​​on the left.

Move up - Use the top negative value.

Move down - use positive values ​​for top.

Note - You can also use the bottom or right values ​​in the same way as top and left.

Three: Fixed Positioning

Fixed positioning allows you to fix the position of an element to a specific location on the page, regardless of scrolling. The specified coordinates will be relative to the browser window.

You can use the top and left values ​​​​and the position attribute to move an HTML element to any position in the HTML document.

Move left - Use negative values ​​for the left side.

Move right - use positive values ​​on the left.

Move up - Use the top negative value.

Move down - use positive values ​​for top.

Note - You can also use the bottom or right values ​​in the same way as top and left.

The above is about how to use css for positioning? Full explanation of css layout and positioning. If you want to know more about CSS tutorial, please pay attention to php Chinese website.


The above is the detailed content of How to use css for positioning? Detailed explanation of CSS layout and positioning. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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