学习了绝对定位以后,对此进行一个总结,啦啦啦啦~
绝对定位特性
1、破坏性
破坏了原有的位置,从文档流里脱离出来
2、包裹性
如果下面这种情况,父级元素将不会有高度和宽度,失去原有的大小
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAAB1CAIAAAAJA342AAAHMklEQVR4nO3ZW0xTdxzAcZ9N8KFP28uWmT1tQR+WbU8sS0x0y8YWnZtxUaeByuKAoE4y2RoPZ7OrbdNSag8V2tLLqdwvLRd7PIWWs244AhPwEgKuMxZQLj2E0rE2vfz3cExD5qiFXar+f798H0hTaPv7nPPvA1sQTFZnS7bfAO4DAFmehwDmUg2UCgAAAO8AAADwDgAAAO8AAADwDgAAAO8AAADwDgAAAO8AAADwDgAAAO8AAADwDgAAAO8AAADwDgAAAO8AAADwDgAAAO8AAADwDgAAAO8AAADwDgAAAO8AAADwDgAAAO8AAADwDgAAAO8AAADwDgAAAO8AAADwDgAAAO8AAADwDgAAAO8AAADwDgAAAO8AAADwDgAAAO8AAADwDgAAAO8AAADwDgAAAO8AAADwDgAAAO8AAADwDgAAAO8AAADwDgAAYIOpvvs+61vDF4AgCIQ4giCyvjgcAYTtCz0zBk8NwNrtP0sGWQDYxDy6/ZTBv/j+nvnZJMB62weDjc5mANJvHww2NA8BLBYjkdlYLPrHbl/IbKYy/Js4jMViTAdAZHBRQ/8kYp0jAQAAAI8A4CkHiK70Owprrtc3ZP2TPKVtBuCez+khTP8QYHn5it0uycvbQZIFqQdHRgy7dr2Wk7O1pOSjYLAbIW51lZVKj4tE23Jzt7tcymRy4P/Zy9ycQ6sty83dTtMS4ZFkcsDlUubmbheJtkmlx1dXWYS4YLC7pOSjnJytu3a9NjJiyALApqNpicn0lV5/OgUwN+c4cmTP+Hh9IuG12b5RqYqTyQGalpBkQSTinp5uKyh4z+9v/B+2H497FIoT3d0Xzp49lAKYmKAPHdodCLRGIm6p9Hhb27fxuEcqPW42VyQS3hs3zGJxPs/3/IcA96/3XP5QIxMRqhe+FQ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mZk72touBIOWhw8V6elbx8ZaYvHodHUI0aOj6srKEuYxMzKiFol4Tme3Uins6ZHEOv7JSf38fB9CtN9vjvp8Yrp4FG63QSTivXihX1gwq1Q1zGMmELAolUKDQTIyohYKuU7nm4t7CZ6g32IXKbifsJW7K/5obGZ4BmXNzEcDpuM2DbPy9Iihda9gSNUW63AZGFZEbDahy6Xdtu1LFouVkrKhvf2C39/PnOXz5zOSktampGy4ebMqDBP+w40bP2NO9Fs8CNEDA5Jdu7YwG+zr44dC1vAumGRnp3q9Rr1ezHztWFJyaWBAyVzCNTWlN27I0euny6NHHfGvs/hdPAq328DlFlEUxWYXNjZWMBOj3d4kEnFnZ40I0Wp1rVz+5sb9/35rEDm5rVojJ7dECjzAA11ugQfrRudJ/L+lkH81kT/ofK9f6nzIxSPAAzwkFo8AD/CQWDwCPMBDYvEI8AAPicUjwAM8JBaPAA/wkFg8AjzAQ2LxCPAAD4nFI8ADPCQWjwAP8JBYPAI8wENi8QjwAA+JxSPAAzwkFo8AD/CQWDwCPMBDYvEI8AAPicUjwAM8JBaPAA/wkFg8AjzAQ2LxCPAAD4nFI8ADPCQWjwAP8JBYPAI8wENi8QjwAA+JxSPAAzwkFo8AD/CQWDwCPMBDYvEI8AAPicUjwAM8JBaPAA/wkFg8AjzAQ2LxCPAAD4nFI8ADPCQWjwAPKTwQ/AI8WOdv/POdwykXO/sAAAAASUVORK5CYII=" alt="" />
<div>
<div style="width: 100px;height: 100px;position: absolute;background:red;"></div>
</div>
3、去浮动
设置绝对定位以后,浮动的元素将会失效,来看下面的效果
b {
display: inline-block;
float: right;
width: 18px;
height: 30px;
background: url(../images/icon.png) no-repeat;
background-position: -154px -42px;
}
效果:
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAqsAAAApCAIAAACdnvdcAAAFVElEQVR4nO3dv4/mRh3Hcf8TeZRrVkJBD8qRB6V5JBRlqJ7SDcKdJYRiOhcg/wnTjYSAh86dBQUGGgsKlxY00z0do9xdYpJcRgm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WnVe9FxDX52SpJktW66EaRYwFhKUGMbWksqwIAAPF6+vTh/bcevew+ABERV+/W27xxIq5JV+vtMouftVMsGEymW+v7eS2Aa/K8cSLWqKoPcnVF4fUbuT454JrSWN9Xu2Lf2jGcLq6q4asHAQAgMq9oLYCIWJPVzveVuvaVHrFmu0wNTAadNmOwJtNDkDBotXzFZ6jUsXIfDvWUD44JwHdlfnNhYBh7k6u9FXH1bhrmeKWxLevnfpEIAIAYvKIEEAadzr34rsmnwvyRH/T29Bp/+iJQONT57tjCZ/Vmnjk4NMUu3du57++wXzKCtybdTQ0E3nUmU5luD15k7E6xw5pNNYiI9NWGxYEAgHhdnl88evO7j95592UmAN8WeXur8c7VKpnn8/P9aU5+SQBjk+f1IYhr0qmPL9vbIMGatGiWNoEkSZKVKq8ECm9NWrR/NtlcDxjbIi2n40VEJNh9vj1LkrNtTgkAABCzED764Y8+/vFPXu7/BQAAAP9zLi/v+vgXEgAAAHEiAQAAECMSAAAAMSIBAAAQIxIAAAAxIgEAABAjEgAAADEiAQAAECMSAAAAMSIBAAAQIxIAAAAxupkAAABAJE4JAAAAxIYEAABAjP4NXelJkAA7lRkAAAAASUVORK5CYII=" alt="" />
加上position:absolute以后
b {
position: absolute;
display: inline-block;
float: right;
width: 18px;
height: 30px;
background: url(../images/icon.png) no-repeat;
background-position: -154px -42px;
}
效果:
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAqUAAAAnCAIAAAC5XaafAAAFWElEQVR4nO3dsY/0RhnHcf8TWeVtTkJBi/KSRWlWQlGGaks3CHeWEIrpXID2T5huJAQsnTsLCgw0FhQuLWim245R3vdNhiRvRgl3moj3zT31S2F7d+9uE12iIHjN96PV6WR5x3vb/GaeZ+xLXrx44b0XAAAwXwl5DwDA7JH3AADMH3kPAMD8kfcAAMwfeQ8AwPyR9wAAzB95DwDA/JH3AADMH3kPAMD8kfcAAMzfvPL+s88+euenT3/2c7m+/m9/FAAA/ofcK+97nRzpXkRcVez2509N63E0u9v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EMQYRYz4PFkRMqAiIyRxA2KpdrCRX9n156b5diSITAAIo5j0zr5nS+E5bIMhzDmbJaEUwbTG6PIOifjMYj4Pwy9VMWngAKAUiCaWZxH7KyRUjpbz9c/XgacFm02u6YAAAAASUVORK5CYII=" alt="" />跑到购物系统的后面,而不是在,左上角,如果设置了left,top等的值,aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA8AAAARCAIAAACNaGH2AAAB9ElEQVQokW2Sz2pTQRTG70ootqZVca1StKTUnfgGgoIPIfgCijaI0q7FRduk+gDiSl9CEt2EljRgEizElMTcaPDmzsz5zpl78+eOi5sGUnsWM8Ocb76Z4ft5zMzMSEeARXgYs7VAujdX3nQG0ja0Nr6PwYBFAPD8GW+qJCIimUzUweHx3Xt/PnwU50gpJppTE4GZCYAxnCRBsfT9woK/s2uTBGF41ns4FKM0aU1K8WgUfCnWM5f9vbyMxxQE0BrGTB8JeMORJbYcRbBWnAvL5dpipvfufeQcAIkjieP0Y8zsmVCpRiOoVILKUfjjuP/pc+3SSmdrO2w2g4PD4KgaVKsm+Dv17tcavfsPOjdW29mNTnajtXq7fuVa8/rNX+t32mvZ9tp6+1Y2KJXYWiLy5KTVe/PWf/qsm3vpv3rdefyktnL158NHva3t7vPN7mau+yKn6g0WISLPTawmEDMB7NygXK4tZvzCvjhHWkMEIrNAPBJJswQgzg2+fqsvLfcK+9Y5aM3MfKpmZq/vnFWaiGAMT5JBsVRfWvb38pIkCEMQYRYz4PFkRMqAiIyRxA2KpdrCRX9n156b5diSITAAIo5j0zr5nS+E5bIMhzDmbJaEUwbTG6PIOifjMYj4Pwy9VMWngAKAUiCaWZxH7KyRUjpbz9c/XgacFm02u6YAAAAASUVORK5CYII=" alt="" />加号的位置就会发生改变了