1: position
- Static static
All tags are static by default static,Unable to change position static The default value is no positioning. It cannot be used as a reference for absolute positioning, and the label object is set left,top Equivalence does not work.
1.relative
- Move relative to the original position of the label
Relative positioning is relative to the original position of the element in the document stream, that is, taking its original position as the reference. Interestingly, even if the relative positioning and offset value of the element are set, the element still occupies the original position, that is, occupies the document flow space. Object follows the normal document flow, but will be based on top,right,bottom,left And other properties are offset in the normal document flow. And its cascade through z-index Attribute definition. be careful: position: relative One of the main uses of: it is convenient to absolutely locate elements and find references.
2.absolute (absolute positioning)
-
Move relative to the positioned parent label (if there is no parent label, take the body as the reference)
-
definition:
The element box set to absolute positioning is completely deleted from the document stream and positioned relative to the nearest positioned ancestor element. If the element has no positioned ancestor element, its position is relative to the original containing block (i.e body Element). The space originally occupied by the element in the normal document flow is closed as if the element did not exist. After the element is located, a block level box is generated, regardless of the type of box it originally generated in the normal flow.
- a key
If the parent is set position Properties, such as position:relative;,Then the child element will be positioned with the upper left corner of the parent as the original point. This can well solve the label deviation problem of adaptive websites, that is, if the parent is adaptive, my child elements will be set position:absolute;Parent element settings position:relative;,then Top,Right,Bottom,Left Expressed as a percentage of width.
- In addition, the object is separated from the normal document flow, and the top, right, bottom, left and other attributes are used for absolute positioning. Its cascade is defined by the z-index attribute.
- object of reference:
 instructions:
xxxxxxxxxx The browser gives priority to displaying text content. If it finds that the text content is blocked, it will try its best to find a place to display it
5: Verify that floating and positioning are out of the document flow (verify that the original location is retained)
1. What is off document flow?
The original position is gone and can be replaced
2. Verification object (method capable of changing label position)
float Relative positioning Absolute positioning Fixed positioning
3. (not separated from document flow)
- Relative positioning
4. Break away from document flow
- 1. Floating
- 2. Determine positioning
- 3. Fixed positioning
5. Test relative positioning
<body> /*Relative movement 500 to the right*/ <div style="height: 100px;width: 200px;background-color: red;position: relative;left: 500px;"></div> <div style="height: 100px;width: 200px;background-color: greenyellow"></div> </body>
6. Test absolute positioning
<body> <div style="height: 100px;width: 200px;background-color: red;position: absolute;left: 500px;"></div> <div style="height: 100px;width: 200px;background-color: greenyellow"></div> </body>
7. Test fixed positioning
<body> <div style="height: 100px;width: 200px;background-color: red;position: fixed;left: 500px;"></div> <div style="height: 100px;width: 200px;background-color: greenyellow"></div> </body>
6: Modal box case of z-index
1. What is a modal box?
- Baidu login page is actually a three-tier structure
1.At the bottom is normal content(z=0) Farthest layer 2.Black transparent area(z=99) Middle layer 3.White registration area(z=100) Closest to user
2.z-index mode box
#d1 { z-index: 99; }
3. Set the stacking order of objects
-
- The z-index value indicates who is pressing who. The large value covers the small value,
-
- Only positioned elements can have z-index, that is, z-index can be used regardless of relative positioning, absolute positioning and fixed positioning, while floating elements cannot use z-index
-
- The z-index value has no unit, but is a positive integer. The default z-index value is 0. If everyone has no z-index value, or the z-index value is the same, who writes behind the HTML, who presses others on it, locates the element, and always suppresses the element without positioning.
-
- From the father phenomenon: when the father counsels, the son is useless
4. Simple z-index modal box
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style> body { margin: 0; } .cover { /*Fixed positioning*/ position: fixed; /*0 up, down, left and right*/ left: 0; top: 0; right: 0; bottom: 0; /*background color */ background-color: rgba(0,0,0,0.4); /*Modal box*/ z-index: 99; } .modal { /*background color */ background-color: white; height: 200px; width: 400px; /*Fixed positioning*/ position: fixed; /*50% from left to right*/ left: 50%; /*50% from top to bottom*/ top: 50%; /*Modal box*/ z-index: 100; /*Move from right to left*/ margin-left: -200px; /*Move from bottom to top*/ margin-top: -100px; } </style> </head> <body> <div>This is the bottom page content</div> <div class="cover"></div> <div class="modal"> <h1>Baidu login</h1> <p>username:<input type="text"></p> <p>password:<input type="text"></p> <button>Point me</button> </div> </body> </html>
7: Transparency
1.opacity effect
transparency opacity It can not only change the transparency of color, but also change the transparency of font
- rgba : Only color can be affected
- opacity: you can modify the color and font