Hướng dẫn position trong css w3schools
ExamplePosition an element: h2 { Try it Yourself » More "Try it Yourself" examples below. Definition and UsageThe
Browser SupportThe numbers in the table specify the first browser version that fully supports the property.
Note: The CSS Syntaxposition: static|absolute|fixed|relative|sticky|initial|inherit; Property Values
More ExamplesExampleHow to position an element relative to its normal position: h2.pos_left { h2.pos_right { Try it Yourself » ExampleMore positioning:
#parent1 { #child1 { #parent2 { #child2 { Try it Yourself » Related PagesCSS tutorial: CSS Positioning HTML DOM reference: position property The The position PropertyThe There are five different position values:
Elements are then positioned using the top, bottom, left, and right
properties. However, these properties will not work unless the position: static;HTML elements are positioned static by default. Static positioned elements are not affected by the top, bottom, left, and right properties. An element with This
element has position: static; Here is the CSS that is used: position: relative;An element with Setting the top, right, bottom, and left properties of a relatively-positioned element will cause it to be adjusted away from its normal position. Other content will not be adjusted to fit into any gap left by the element. This element has position: relative; Here is the CSS that is used: Example div.relative { Try it Yourself » position: fixed;An element with A fixed element does not leave a gap in the page where it would normally have been located. Notice the fixed element in the lower-right corner of the page. Here is the CSS that is used: Example div.fixed { Try it Yourself » This element has position: fixed; position: absolute;An element with However; if an absolute positioned element has no positioned ancestors, it uses the document body, and moves along with page scrolling. Note: Absolute positioned elements are removed from the normal flow, and can overlap elements. Here is a simple example: This element has position: relative; This element has position: absolute;
Here is the CSS that is used: Example div.relative { div.absolute { Try it Yourself » position: sticky;An element with A sticky element toggles between Note: Internet Explorer does not support sticky positioning. Safari requires a -webkit- prefix (see example below). You must also specify at least one of In this example, the sticky element sticks to the top of the page ( Example div.sticky { Try it Yourself » Positioning Text In an ImageHow to position text over an image: More ExamplesSet the shape of an element All CSS Positioning Properties
|