1.relative:相對定位
說明:定位元素相對原來的自己進行定位的方式,脫離普通的文檔流,依然佔用原來空間
<!doctype html><htmllang="en"><head><metacharset="UTF-8"><metaname="Generator"content="EditPlus"><metaname="Author"content=""><metaname="Keywords"content=""><metaname="Description"content=""><title>Document</title><styletype="text/css">div{width:100px;height:100px;border:1px solid red;position:relative;left:100px;top:100px;}</style></head><body><div></div><p>我的公眾號名稱:吾愛樂享</p></body></html>2.absolute:絕對定位
說明:定位元素相對與它的上級來說的一種定位方式,上級就是只父類或上上級或者body,一級一級的往上找其他定位(固定和相對),直到找到為止,如果沒有就會選擇body作為上級
<!doctype html><htmllang="en"><head><metacharset="UTF-8"><metaname="Generator"content="EditPlus"><metaname="Author"content=""><metaname="Keywords"content=""><metaname="Description"content=""><title>Document</title><styletype="text/css">.box{width:100px;height:100px;border:1px solid red;position:relative;}.absolute{width:200px;height:200px;border:1px solid blue;position:absolute;left:0px;top:0px;}</style></head><body><divclass="box"><divclass="absolute"></div></div><p>我的公眾號名稱:吾愛樂享</p></body></html>案例:
<!doctype html><htmllang="en"><head><metacharset="UTF-8"><metaname="Generator"content="EditPlus"><metaname="Author"content=""><metaname="Keywords"content=""><metaname="Description"content=""><title>Document</title><styletype="text/css">*{padding:0px;margin:0px;}li{list-style:none;