Home > Article > Web Front-end > A detailed analysis of the positioning of the CSS box model
1, Static Positioning
## The default value for #HTML elements is that there is no positioning and the element appears in the normal flow.
Static positioned elements will not be affected by top, bottom, left, right.
It does not move even if the window is scrolled:
Fixed positioned elements overlap with other elements.
absolutely positioned elements.
Absolutely positioned elements overlap with other elements.
Elements are positioned independently of the document flow, so they can cover
other elements on the page
z-index Attribute specifies the stacking order of an element (which element should be in front, or behind) An element can have a positive or negative stacking order:
Elements with a higher stacking order are always in The front of lower stacking order elements.
Note: If two positioned elements overlap and z-index is not specified, the element last positioned in the HTML code will be displayed first.
1. The
object that will be assigned this positioning methodfrom Drag it out of the document flow and use left, right, top, bottom and other attributes to perform absolute positioning relative to its closest parent object with the most positioning settings. If the object's parent does not set positioning attributes, it still follows HTML positioning. If it is regular, it will be positioned based on the upper left corner of the body object as a reference. 2. Absolutely positioned objects can be stacked, and the stacking order can be controlled through the z-index attribute. The z-index value is a unitless
integer, with the larger one on top and can have negative values. Relative to the nearest non-standard stream positioning, the original position disappears and is replaced by the subsequent position
Relative to the original position, but the original position is still retained .
Objects cannot be stacked, and their positions are offset in the normal document flow according to left, right, top, bottom and other attributes.
You can also use z-index hierarchical design.
<meta charset="UTF-8" /> <title></title> <style type="text/css"> /*多个标签同时设置,使用逗号分隔*/ body, p, ul, li, img, a { margin: 0; padding: 0; } /*给定图片尺寸:否则会超出父容器,堆叠在一起*/ img { width: 100%; height: 100% } /*让a标签绝对于li标签,li要设置relative*/ li { list-style: none; position: relative; float: left; padding: 1%; width: 18%; } /*让删除红叉处于li的右上角,且需给定大小*/ a { background: url(images/close.png); width: 16px; height: 16px; position: absolute; top: 0; right: 0; }</style>
The above is the detailed content of A detailed analysis of the positioning of the CSS box model. For more information, please follow other related articles on the PHP Chinese website!