The relative positioning method of images is to use the position attribute of CSS, the top, right, bottom and left attributes of CSS, the transform attribute of CSS and the flex layout of CSS. Detailed introduction: 1. Use the position attribute of CSS, including four values: static positioning, relative positioning, absolute positioning and fixed positioning; 2. Use the top, right, bottom and left attributes of CSS, etc.
The operating system for this tutorial: Windows 10 system, DELL G3 computer.
Relative image positioning is an image layout method often used in web design. It allows images to be positioned relative to each other based on the size and position of page elements, thereby achieving seamless integration between images and page elements. . Specifically, the image relative positioning method can be implemented based on the following aspects:
1. Use the position attribute of CSS
The position attribute of CSS is used to define elements Position on the page, including static (static positioning), relative (relative positioning), absolute (absolute positioning) and Fixed (fixed positioning) four values. Among them, relative positioning (relative) is the most commonly used value in the image relative positioning method.
1. Static positioning (static): Static positioning is the default positioning method of elements, and the elements are arranged according to the normal document flow. In this positioning method, the element will not be affected by top, right, bottom and the influence of attributes such as left.
2. Relative positioning (relative): Relatively positioned elements will be adjusted according to their position in the normal document flow. You can set top, right, bottom and left and other attributes to change the position of the element. Relatively positioned elements remain in the document flow and have no impact on other elements.
3. Absolute positioning (absolute): Absolutely positioned elements will break away from the document flow, relative to their nearest non-static The positioned ancestor element is positioned. If there are no ancestor elements, positioning is relative to the original containing block of the document. You can set top, right, bottom and left and other attributes to change the position of the element. Absolutely positioned elements have an impact on other elements.
4. Fixed positioning (fixed): Fixed-positioned elements will break away from the document flow and be positioned relative to the browser window. You can set top, right, bottom and left and other attributes to change the position of the element. Fixed positioned elements have an impact on other elements.
2. Use the top, right, bottom and left properties of CSS
In the relative positioning method, you can set the top, right, bottom and left properties of CSS Properties to precisely control the position of the image. These properties are used to set the horizontal and vertical position of the image respectively.
1. top: Set the distance between the image and the top edge of the nearest non-statically positioned ancestor element.
2. right: Set the distance between the image and the right edge of the nearest non-statically positioned ancestor element.
3. Bottom: Set the distance between the image and the bottom edge of the nearest non-statically positioned ancestor element.
4. left: Set the distance between the image and the bottom edge of the nearest non-statically positioned ancestor element.
It should be noted that the values of the top, right, bottom and left attributes can be pixel values, percentage values or keywords (such as: auto, inherit, initial wait). In actual use, you can choose flexibly according to your needs.
3. Use the transform attribute of CSS
The transform attribute of CSS can transform elements such as rotation, scaling, translation and tilt. In the relative positioning method, you can use transform Properties to adjust the size and position of the image.
1. translate(): used to set the translation of elements in the horizontal and vertical directions. The translation distance can be controlled by setting the x and y properties.
2. scale(): used to set the scaling ratio of elements. You can control the horizontal and vertical scaling by setting the scaleX and scaleY properties.
3. rotate(): used to set the rotation angle of the element. You can control the horizontal and vertical rotation angles by setting the rotateX and rotateY properties.
4. skew(): used to set the tilt angle of the element. You can control the horizontal and vertical tilt angles by setting the skewX and skewY properties.
4. Flex layout using CSS
Flex layout is a modern and flexible layout method that can easily achieve seamless separation between images and page elements. Seam fusion. In flex layout, you can set flex-grow, flex-shrink and flex-basis properties to control the size of the image by setting justify-content and align-items Properties to control the position of the image.
1. flex-grow: Set the magnification ratio of the element in the vertical or horizontal direction. When the screen size changes, elements will flex-grow The value automatically resizes to fit the new screen size.
2. flex-shrink: Set the shrinkage ratio of the element in the vertical or horizontal direction. When the screen size changes, the element will flex-shrink The value automatically resizes to fit the new screen size.
3. flex-basis: Set the base size of the element in the vertical or horizontal direction. When the screen size changes, the element will be adjusted according to the value of flex-basis and The values of flex-grow and flex-shrink are automatically resized to fit the new screen size.
4. justify-content: Set the horizontal alignment of the element. Possible values: flex-start (aligned at the starting point), flex-end (aligned at the end), center (aligned in the center), space-between (aligned at both ends, equal intervals between elements) and space-around (equal space on both sides of each element).
The above is the detailed content of What is the relative positioning method of images?. For more information, please follow other related articles on the PHP Chinese website!