The offset does not affect the position of any other elements; thus, the space given for the element in the page layout is the same as if position were static. Toutefois, les éléments positionnés de façon absolue et qui ne sont pas des éléments remplacés peuvent remplir l'espa… An element with position: relative; is positioned relative to its normal position. Relative Positioning. They can likewise be made to fill the available horizontal space by specifying both left and right and leaving width as auto. Most of the time, absolutely positioned elements that have height and width set to auto are sized so as to fit their contents. La propiedad position de CSS especifica cómo un elemento es posicionado en el documento. The absolutely positioned element is positioned relative to its Fixed positioning is similar to absolute positioning, with the exception that the element's Sticky positioning can be thought of as a hybrid of relative and fixed positioning. The "B" heading will appear just below the items that begin with "A" until they are scrolled offscreen. In the example below, note how the other elements are placed as if "Two" were taking up the space of its normal location.Elements that are relatively positioned remain in the normal flow of the document.

position:relative 对 table-*-group, table-row, table-column, table-cell, table-caption 元素无效。 absolute 元素会被移出正常文档流,并不为元素预留空间,通过指定元素相对于最近的非 static 定位祖先元素的偏移,来确定元素位置。 The source for this interactive example is stored in a GitHub repository. Relative positioning uses the same four positioning properties as absolute positioning, but instead of basing the position of the element upon its closest non-statically positioned ancestor, it starts from where the element would be if it were still in the normal flow. The source for this interactive example is stored in a GitHub repository.

If the element is in position relative, the element will move upwards by the amount defined by the bottom value. Sign in to enjoy the benefits of an MDN account. Other content will not be … If the element is in position absolute, the element will position itself from the bottom of the first positioned ancestor. The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out Get the latest and greatest from MDN delivered straight to your inbox.The newsletter is offered in English only at the moment. La plupart du temps, les éléments positionnés de façon absolue ont leurs propriétés height et width qui valent auto afin que le contenu ait suffisamment d'espace. If you'd like to contribute to the interactive examples project, please clone Using the X axis for an example, let's say we have an image that is 300px wide and we are using it in a container that is 100px wide, with background-size set to auto:So that with position percentages of -25%, 0%, 50%, 100%, 125%,  we get these image-to-container edge offset values:So with these resultant values for our example, the It's worth mentioning that if your background-size is equal to the container size for a given axis, then a The compatibility table in this page is generated from structured data. Las propiedades top, right, bottom, y left determinan la ubicación final de los elementos posicionados.

For instance...A common use for sticky positioning is for the headings in an alphabetized list.

Les propriétés top, right, bottom et left déterminent l'emplacement final de l'élément positionné. If you'd like to contribute to the interactive examples project, please clone Most of the time, absolutely positioned elements that have Except for the case just described (of absolutely positioned elements filling the available space):Relatively positioned elements are offset a given amount from their normal position within the document, but without the offset affecting other elements. A stickily positioned element is treated as relatively positioned until it crosses a specified threshold, at which point it is treated as fixed until it reaches the boundary of its parent.
Setting the top, right, bottom, and left properties of a relatively-positioned element will cause it to be adjusted away from its normal position. If you haven’t already created an account, you will be prompted to do so after signing in. The element will scroll along with its container, until it is at the top of the container (or reaches the offset specified in top), and will then stop scrolling, so it stays visible.. Rather than sliding offscreen with the rest of the content, the "B" heading will then remain fixed to the top of the viewport until all the "B" items have scrolled offscreen, at which point it will be covered up by the "C" heading, and so on.Get the latest and greatest from MDN delivered straight to your inbox.The newsletter is offered in English only at the moment.

If you haven’t already created an account, you will be prompted to do so after signing in.

Sign in to enjoy the benefits of an MDN account.