position定位的几种表示
Position的几种表示
-
relative
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Position</title> <style> *{ padding: 0px; margin: 0px; } .div{ height: 100px; width: 100px; background-color: red; } .div1{ height: 100px; width: 100px; background-color: aquamarine; position: relative; left: 200px; top: 100px; } .div2{ height: 100px; width: 100px; background-color: blueviolet; } </style> </head> <body> <div class="div"> 我是div </div> <div class="div1"> 我是div01 </div> <div class="div2"> 我是div02 </div> </body> </html> -
absolute
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Position</title> <style> *{ padding: 0px; margin: 0px; } .div{ height: 100px; width: 100px; background-color: red; } .div_p{ height: 300px; width: 300px; background-color: beige; position: relative; left: 300px; } .div1{ height: 100px; width: 100px; background-color: aquamarine; position: absolute; left: 50px; top: 50px; } .div2{ height: 100px; width: 100px; background-color: coral; } .div4{ height: 100px; width: 100px; background-color: blueviolet; } </style> </head> <body> <div class="div"> 我是div </div> <div class="div_p"> <div class="div1"> 我是div01 </div> <div class="div2"> 我是div02 </div> </div> <div class="div4"> 我是div04 </div> </body> </html> -
fixed
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>fixed</title> <style> *{ padding: 0px; margin: 0px; } .div{ height: 100px; width: 100px; background-color: red; position: fixed; top: 300px; left: 200px; } .div1{ height: 100px; width: 100px; background-color: aquamarine; } .div2{ height: 100px; width: 100px; background-color: blueviolet; } </style> </head> <body> <div class="div"> 我是div </div> <div class="div1"> 我是div01 </div> <div class="div2"> 我是div02 </div> </body> </html>小结
<!-- 1.position relative -不会脱离文档流,原位置依旧会保存 absolute(脱离文档流) -如果父标签不是relative,则以body为原始位置开始移动 -如果父标签是relative,则以父标签为原始位置开始移动 fixed --脱离文档流 static(默认) -->
人生不易,多多努力!!!
浙公网安备 33010602011771号