<span style=
"color: #008080;"
> 1</span> <span style=
"color: #0000ff;"
><!</span><span style=
"color: #ff00ff;"
>DOCTYPE html</span><span style=
"color: #0000ff;"
>></span>
<span style=
"color: #008080;"
> 2</span> <span style=
"color: #0000ff;"
><</span><span style=
"color: #800000;"
>html</span><span style=
"color: #0000ff;"
>></span>
<span style=
"color: #008080;"
> 3</span> <span style=
"color: #0000ff;"
><</span><span style=
"color: #800000;"
>head</span><span style=
"color: #0000ff;"
>></span>
<span style=
"color: #008080;"
> 4</span> <span style=
"color: #0000ff;"
><</span><span style=
"color: #800000;"
>meta </span><span style=
"color: #ff0000;"
>charset</span><span style=
"color: #0000ff;"
>=
"utf-8"
</span><span style=
"color: #0000ff;"
>></span>
<span style=
"color: #008080;"
> 5</span> <span style=
"color: #0000ff;"
><</span><span style=
"color: #800000;"
>title</span><span style=
"color: #0000ff;"
>></span>relative影响最小化<span style=
"color: #0000ff;"
></</span><span style=
"color: #800000;"
>title</span><span style=
"color: #0000ff;"
>></span>
<span style=
"color: #008080;"
> 6</span> <span style=
"color: #0000ff;"
><</span><span style=
"color: #800000;"
>style</span><span style=
"color: #0000ff;"
>></span>
<span style=
"color: #008080;"
> 7</span> <span style=
"background-color: #f5f5f5; color: #800000;"
> * </span><span style=
"background-color: #f5f5f5; color: #000000;"
>{</span>
<span style=
"color: #008080;"
> 8</span> <span style=
"background-color: #f5f5f5; color: #ff0000;"
> margin</span><span style=
"background-color: #f5f5f5; color: #000000;"
>:</span><span style=
"background-color: #f5f5f5; color: #0000ff;"
>0</span><span style=
"background-color: #f5f5f5; color: #000000;"
>;</span>
<span style=
"color: #008080;"
> 9</span> <span style=
"background-color: #f5f5f5; color: #000000;"
>}</span>
<span style=
"color: #008080;"
> 10</span>
<span style=
"color: #008080;"
> 11</span> <span style=
"background-color: #f5f5f5; color: #800000;"
> .wraper </span><span style=
"background-color: #f5f5f5; color: #000000;"
>{</span>
<span style=
"color: #008080;"
> 12</span> <span style=
"background-color: #f5f5f5; color: #ff0000;"
> width</span><span style=
"background-color: #f5f5f5; color: #000000;"
>:</span><span style=
"background-color: #f5f5f5; color: #0000ff;"
>800px</span><span style=
"background-color: #f5f5f5; color: #000000;"
>;</span>
<span style=
"color: #008080;"
> 13</span> <span style=
"background-color: #f5f5f5; color: #ff0000;"
> margin</span><span style=
"background-color: #f5f5f5; color: #000000;"
>:</span><span style=
"background-color: #f5f5f5; color: #0000ff;"
>50px auto</span><span style=
"background-color: #f5f5f5; color: #000000;"
>;</span>
<span style=
"color: #008080;"
> 14</span> <span style=
"background-color: #f5f5f5; color: #ff0000;"
> background-color</span><span style=
"background-color: #f5f5f5; color: #000000;"
>:</span><span style=
"background-color: #f5f5f5; color: #0000ff;"
> #ccc</span><span style=
"background-color: #f5f5f5; color: #000000;"
>;</span>
<span style=
"color: #008080;"
> 15</span> <span style=
"background-color: #f5f5f5; color: #ff0000;"
> border</span><span style=
"background-color: #f5f5f5; color: #000000;"
>:</span><span style=
"background-color: #f5f5f5; color: #0000ff;"
> 3px solid green</span><span style=
"background-color: #f5f5f5; color: #000000;"
>;</span>
<span style=
"color: #008080;"
> 16</span> <span style=
"background-color: #f5f5f5; color: #000000;"
>}</span>
<span style=
"color: #008080;"
> 17</span>
<span style=
"color: #008080;"
> 18</span> <span style=
"background-color: #f5f5f5; color: #800000;"
> .box </span><span style=
"background-color: #f5f5f5; color: #000000;"
>{</span>
<span style=
"color: #008080;"
> 19</span> <span style=
"background-color: #f5f5f5; color: #ff0000;"
> width</span><span style=
"background-color: #f5f5f5; color: #000000;"
>:</span><span style=
"background-color: #f5f5f5; color: #0000ff;"
>500px</span><span style=
"background-color: #f5f5f5; color: #000000;"
>;</span>
<span style=
"color: #008080;"
> 20</span> <span style=
"background-color: #f5f5f5; color: #ff0000;"
> margin</span><span style=
"background-color: #f5f5f5; color: #000000;"
>:</span><span style=
"background-color: #f5f5f5; color: #0000ff;"
>50px auto</span><span style=
"background-color: #f5f5f5; color: #000000;"
>;</span>
<span style=
"color: #008080;"
> 21</span> <span style=
"background-color: #f5f5f5; color: #ff0000;"
> background-color</span><span style=
"background-color: #f5f5f5; color: #000000;"
>:</span><span style=
"background-color: #f5f5f5; color: #0000ff;"
> orange</span><span style=
"background-color: #f5f5f5; color: #000000;"
>;</span>
<span style=
"color: #008080;"
> 22</span> <span style=
"background-color: #f5f5f5; color: #ff0000;"
> border</span><span style=
"background-color: #f5f5f5; color: #000000;"
>:</span><span style=
"background-color: #f5f5f5; color: #0000ff;"
> 3px solid black</span><span style=
"background-color: #f5f5f5; color: #000000;"
>;</span>
<span style=
"color: #008080;"
> 23</span> <span style=
"background-color: #f5f5f5; color: #000000;"
>}</span>
<span style=
"color: #008080;"
> 24</span>
<span style=
"color: #008080;"
> 25</span> <span style=
"background-color: #f5f5f5; color: #800000;"
> img </span><span style=
"background-color: #f5f5f5; color: #000000;"
>{</span>
<span style=
"color: #008080;"
> 26</span> <span style=
"background-color: #f5f5f5; color: #ff0000;"
> border</span><span style=
"background-color: #f5f5f5; color: #000000;"
>:</span><span style=
"background-color: #f5f5f5; color: #0000ff;"
>1px solid blue</span><span style=
"background-color: #f5f5f5; color: #000000;"
>;</span>
<span style=
"color: #008080;"
> 27</span> <span style=
"background-color: #f5f5f5; color: #ff0000;"
> margin</span><span style=
"background-color: #f5f5f5; color: #000000;"
>:</span><span style=
"background-color: #f5f5f5; color: #0000ff;"
>10px</span><span style=
"background-color: #f5f5f5; color: #000000;"
>;</span>
<span style=
"color: #008080;"
> 28</span> <span style=
"background-color: #f5f5f5; color: #000000;"
>}</span>
<span style=
"color: #008080;"
> 29</span>
<span style=
"color: #008080;"
> 30</span> <span style=
"background-color: #f5f5f5; color: #800000;"
> p </span><span style=
"background-color: #f5f5f5; color: #000000;"
>{</span>
<span style=
"color: #008080;"
> 31</span> <span style=
"background-color: #f5f5f5; color: #ff0000;"
> padding-left</span><span style=
"background-color: #f5f5f5; color: #000000;"
>:</span><span style=
"background-color: #f5f5f5; color: #0000ff;"
>10px</span><span style=
"background-color: #f5f5f5; color: #000000;"
>;</span>
<span style=
"color: #008080;"
> 32</span> <span style=
"background-color: #f5f5f5; color: #ff0000;"
> margin</span><span style=
"background-color: #f5f5f5; color: #000000;"
>:</span><span style=
"background-color: #f5f5f5; color: #0000ff;"
>10px</span><span style=
"background-color: #f5f5f5; color: #000000;"
>;</span>
<span style=
"color: #008080;"
> 33</span> <span style=
"background-color: #f5f5f5; color: #000000;"
>}</span>
<span style=
"color: #008080;"
> 34</span>
<span style=
"color: #008080;"
> 35</span> <span style=
"background-color: #f5f5f5; color: #800000;"
> .absolute </span><span style=
"background-color: #f5f5f5; color: #000000;"
>{</span>
<span style=
"color: #008080;"
> 36</span> <span style=
"background-color: #f5f5f5; color: #ff0000;"
> position</span><span style=
"background-color: #f5f5f5; color: #000000;"
>:</span><span style=
"background-color: #f5f5f5; color: #0000ff;"
> absolute</span><span style=
"background-color: #f5f5f5; color: #000000;"
>;</span>
<span style=
"color: #008080;"
> 37</span> <span style=
"background-color: #f5f5f5; color: #000000;"
>}</span>
<span style=
"color: #008080;"
> 38</span>
<span style=
"color: #008080;"
> 39</span> <span style=
"background-color: #f5f5f5; color: #800000;"
> .box2 .absolute </span><span style=
"background-color: #f5f5f5; color: #000000;"
>{</span>
<span style=
"color: #008080;"
> 40</span> <span style=
"background-color: #f5f5f5; color: #ff0000;"
> margin-left</span><span style=
"background-color: #f5f5f5; color: #000000;"
>:</span><span style=
"background-color: #f5f5f5; color: #0000ff;"
> -3px</span><span style=
"background-color: #f5f5f5; color: #000000;"
>;</span>
<span style=
"color: #008080;"
> 41</span> <span style=
"background-color: #f5f5f5; color: #ff0000;"
> margin-top</span><span style=
"background-color: #f5f5f5; color: #000000;"
>:</span><span style=
"background-color: #f5f5f5; color: #0000ff;"
> -3px</span><span style=
"background-color: #f5f5f5; color: #000000;"
>;</span>
<span style=
"color: #008080;"
> 42</span> <span style=
"background-color: #f5f5f5; color: #000000;"
>}</span>
<span style=
"color: #008080;"
> 43</span>
<span style=
"color: #008080;"
> 44</span> <span style=
"background-color: #f5f5f5; color: #800000;"
> .box3 .absolute </span><span style=
"background-color: #f5f5f5; color: #000000;"
>{</span>
<span style=
"color: #008080;"
> 45</span> <span style=
"background-color: #f5f5f5; color: #ff0000;"
> margin-top</span><span style=
"background-color: #f5f5f5; color: #000000;"
>:</span><span style=
"background-color: #f5f5f5; color: #0000ff;"
>-3px</span><span style=
"background-color: #f5f5f5; color: #000000;"
>;</span>
<span style=
"color: #008080;"
> 46</span> <span style=
"background-color: #f5f5f5; color: #ff0000;"
> margin-left</span><span style=
"background-color: #f5f5f5; color: #000000;"
>:</span><span style=
"background-color: #f5f5f5; color: #0000ff;"
>450px</span><span style=
"background-color: #f5f5f5; color: #000000;"
>;</span>
<span style=
"color: #008080;"
> 47</span> <span style=
"background-color: #f5f5f5; color: #000000;"
>}</span>
<span style=
"color: #008080;"
> 48</span>
<span style=
"color: #008080;"
> 49</span> <span style=
"background-color: #f5f5f5; color: #800000;"
> .box4 .relative </span><span style=
"background-color: #f5f5f5; color: #000000;"
>{</span>
<span style=
"color: #008080;"
> 50</span> <span style=
"background-color: #f5f5f5; color: #ff0000;"
> position</span><span style=
"background-color: #f5f5f5; color: #000000;"
>:</span><span style=
"background-color: #f5f5f5; color: #0000ff;"
> relative</span><span style=
"background-color: #f5f5f5; color: #000000;"
>;</span>
<span style=
"color: #008080;"
> 51</span> <span style=
"background-color: #f5f5f5; color: #ff0000;"
> border</span><span style=
"background-color: #f5f5f5; color: #000000;"
>:</span><span style=
"background-color: #f5f5f5; color: #0000ff;"
>2px solid red</span><span style=
"background-color: #f5f5f5; color: #000000;"
>;</span>
<span style=
"color: #008080;"
> 52</span> <span style=
"background-color: #f5f5f5; color: #000000;"
>}</span>
<span style=
"color: #008080;"
> 53</span>
<span style=
"color: #008080;"
> 54</span> <span style=
"background-color: #f5f5f5; color: #800000;"
> .box4 .absolute </span><span style=
"background-color: #f5f5f5; color: #000000;"
>{</span>
<span style=
"color: #008080;"
> 55</span> <span style=
"background-color: #f5f5f5; color: #ff0000;"
> top</span><span style=
"background-color: #f5f5f5; color: #000000;"
>:</span><span style=
"background-color: #f5f5f5; color: #0000ff;"
>-10px</span><span style=
"background-color: #f5f5f5; color: #000000;"
>;</span>
<span style=
"color: #008080;"
> 56</span> <span style=
"background-color: #f5f5f5; color: #ff0000;"
> right</span><span style=
"background-color: #f5f5f5; color: #000000;"
>:</span><span style=
"background-color: #f5f5f5; color: #0000ff;"
>-10px</span><span style=
"background-color: #f5f5f5; color: #000000;"
>;</span>
<span style=
"color: #008080;"
> 57</span> <span style=
"background-color: #f5f5f5; color: #000000;"
>}</span>
<span style=
"color: #008080;"
> 58</span> <span style=
"color: #0000ff;"
></</span><span style=
"color: #800000;"
>style</span><span style=
"color: #0000ff;"
>></span>
<span style=
"color: #008080;"
> 59</span> <span style=
"color: #0000ff;"
></</span><span style=
"color: #800000;"
>head</span><span style=
"color: #0000ff;"
>></span>
<span style=
"color: #008080;"
> 60</span> <span style=
"color: #0000ff;"
><</span><span style=
"color: #800000;"
>body</span><span style=
"color: #0000ff;"
>></span>
<span style=
"color: #008080;"
> 61</span> <span style=
"color: #0000ff;"
><</span><span style=
"color: #800000;"
>div </span><span style=
"color: #ff0000;"
>
class
</span><span style=
"color: #0000ff;"
>=
"wraper"
</span><span style=
"color: #0000ff;"
>></span>
<span style=
"color: #008080;"
> 62</span> <span style=
"color: #0000ff;"
><</span><span style=
"color: #800000;"
>div </span><span style=
"color: #ff0000;"
>
class
</span><span style=
"color: #0000ff;"
>=
"box box1"
</span><span style=
"color: #0000ff;"
>></span>
<span style=
"color: #008080;"
> 63</span> <span style=
"color: #0000ff;"
><</span><span style=
"color: #800000;"
>img </span><span style=
"color: #ff0000;"
>src</span><span style=
"color: #0000ff;"
>=
"http://image.tianjimedia.com/uploadImages/2012/237/4134F4528419.jpg"
</span><span style=
"color: #ff0000;"
> alt</span><span style=
"color: #0000ff;"
>=
"A picture"
</span><span style=
"color: #ff0000;"
> style</span><span style=
"color: #0000ff;"
>=
"width:50px;height:30px"
</span> <span style=
"color: #0000ff;"
>/></span>
<span style=
"color: #008080;"
> 64</span> <span style=
"color: #0000ff;"
><</span><span style=
"color: #800000;"
>img </span><span style=
"color: #ff0000;"
>src</span><span style=
"color: #0000ff;"
>=
"http://imgsrc.baidu.com/forum/w%3D580/sign=0c101fe665380cd7e61ea2e59145ad14/f9a3492762d0f7032de1758a08fa513d2797c542.jpg"
</span><span style=
"color: #ff0000;"
> alt</span><span style=
"color: #0000ff;"
>=
"A picture"
</span><span style=
"color: #ff0000;"
> style</span><span style=
"color: #0000ff;"
>=
"width:100px;height:150px"
</span> <span style=
"color: #0000ff;"
>/></span>
<span style=
"color: #008080;"
> 65</span> <span style=
"color: #0000ff;"
><</span><span style=
"color: #800000;"
>img </span><span style=
"color: #ff0000;"
>src</span><span style=
"color: #0000ff;"
>=
"http://imgsrc.baidu.com/forum/w%3D580/sign=0c101fe665380cd7e61ea2e59145ad14/f9a3492762d0f7032de1758a08fa513d2797c542.jpg"
</span><span style=
"color: #ff0000;"
> alt</span><span style=
"color: #0000ff;"
>=
"A picture"
</span><span style=
"color: #ff0000;"
> style</span><span style=
"color: #0000ff;"
>=
"width:100px;height:150px"
</span> <span style=
"color: #0000ff;"
>/></span>
<span style=
"color: #008080;"
> 66</span> <span style=
"color: #0000ff;"
><</span><span style=
"color: #800000;"
>img </span><span style=
"color: #ff0000;"
>src</span><span style=
"color: #0000ff;"
>=
"http://imgsrc.baidu.com/forum/w%3D580/sign=0c101fe665380cd7e61ea2e59145ad14/f9a3492762d0f7032de1758a08fa513d2797c542.jpg"
</span><span style=
"color: #ff0000;"
> alt</span><span style=
"color: #0000ff;"
>=
"A picture"
</span><span style=
"color: #ff0000;"
> style</span><span style=
"color: #0000ff;"
>=
"width:100px;height:150px"
</span> <span style=
"color: #0000ff;"
>/></span>
<span style=
"color: #008080;"
> 67</span> <span style=
"color: #0000ff;"
><</span><span style=
"color: #800000;"
>p</span><span style=
"color: #0000ff;"
>></span>这是没有任何定位,正常流的样子。<span style=
"color: #0000ff;"
></</span><span style=
"color: #800000;"
>p</span><span style=
"color: #0000ff;"
>></span>
<span style=
"color: #008080;"
> 68</span> <span style=
"color: #0000ff;"
><</span><span style=
"color: #800000;"
>p</span><span style=
"color: #0000ff;"
>></span>后续。。。<span style=
"color: #0000ff;"
></</span><span style=
"color: #800000;"
>p</span><span style=
"color: #0000ff;"
>></span>
<span style=
"color: #008080;"
> 69</span> <span style=
"color: #0000ff;"
></</span><span style=
"color: #800000;"
>div</span><span style=
"color: #0000ff;"
>></span>
<span style=
"color: #008080;"
> 70</span> <span style=
"color: #0000ff;"
></</span><span style=
"color: #800000;"
>div</span><span style=
"color: #0000ff;"
>></span><span style=
"color: #008000;"
><!--</span><span style=
"color: #008000;"
>关闭wraper</span><span style=
"color: #008000;"
>--></span>
<span style=
"color: #008080;"
> 71</span> <span style=
"color: #0000ff;"
><</span><span style=
"color: #800000;"
>div </span><span style=
"color: #ff0000;"
>
class
</span><span style=
"color: #0000ff;"
>=
"wraper"
</span><span style=
"color: #0000ff;"
>></span>
<span style=
"color: #008080;"
> 72</span> <span style=
"color: #0000ff;"
><</span><span style=
"color: #800000;"
>div </span><span style=
"color: #ff0000;"
>
class
</span><span style=
"color: #0000ff;"
>=
"box box2"
</span><span style=
"color: #0000ff;"
>></span>
<span style=
"color: #008080;"
> 73</span> <span style=
"color: #0000ff;"
><</span><span style=
"color: #800000;"
>img </span><span style=
"color: #ff0000;"
>
class
</span><span style=
"color: #0000ff;"
>=
"absolute"
</span><span style=
"color: #ff0000;"
> src</span><span style=
"color: #0000ff;"
>=
"http://image.tianjimedia.com/uploadImages/2012/237/4134F4528419.jpg"
</span><span style=
"color: #ff0000;"
> alt</span><span style=
"color: #0000ff;"
>=
"A picture"
</span><span style=
"color: #ff0000;"
> style</span><span style=
"color: #0000ff;"
>=
"width:50px;height:30px"
</span> <span style=
"color: #0000ff;"
>/></span>
<span style=
"color: #008080;"
> 74</span> <span style=
"color: #0000ff;"
><</span><span style=
"color: #800000;"
>img </span><span style=
"color: #ff0000;"
>src</span><span style=
"color: #0000ff;"
>=
"http://imgsrc.baidu.com/forum/w%3D580/sign=0c101fe665380cd7e61ea2e59145ad14/f9a3492762d0f7032de1758a08fa513d2797c542.jpg"
</span><span style=
"color: #ff0000;"
> alt</span><span style=
"color: #0000ff;"
>=
"A picture"
</span><span style=
"color: #ff0000;"
> style</span><span style=
"color: #0000ff;"
>=
"width:100px;height:150px"
</span> <span style=
"color: #0000ff;"
>/></span>
<span style=
"color: #008080;"
> 75</span> <span style=
"color: #0000ff;"
><</span><span style=
"color: #800000;"
>img </span><span style=
"color: #ff0000;"
>src</span><span style=
"color: #0000ff;"
>=
"http://imgsrc.baidu.com/forum/w%3D580/sign=0c101fe665380cd7e61ea2e59145ad14/f9a3492762d0f7032de1758a08fa513d2797c542.jpg"
</span><span style=
"color: #ff0000;"
> alt</span><span style=
"color: #0000ff;"
>=
"A picture"
</span><span style=
"color: #ff0000;"
> style</span><span style=
"color: #0000ff;"
>=
"width:100px;height:150px"
</span> <span style=
"color: #0000ff;"
>/></span>
<span style=
"color: #008080;"
> 76</span> <span style=
"color: #0000ff;"
><</span><span style=
"color: #800000;"
>img </span><span style=
"color: #ff0000;"
>src</span><span style=
"color: #0000ff;"
>=
"http://imgsrc.baidu.com/forum/w%3D580/sign=0c101fe665380cd7e61ea2e59145ad14/f9a3492762d0f7032de1758a08fa513d2797c542.jpg"
</span><span style=
"color: #ff0000;"
> alt</span><span style=
"color: #0000ff;"
>=
"A picture"
</span><span style=
"color: #ff0000;"
> style</span><span style=
"color: #0000ff;"
>=
"width:100px;height:150px"
</span> <span style=
"color: #0000ff;"
>/></span>
<span style=
"color: #008080;"
> 77</span> <span style=
"color: #0000ff;"
><</span><span style=
"color: #800000;"
>p</span><span style=
"color: #0000ff;"
>></span>如果我们要将图像定位到黑色边框的左上角,应该怎么办?<span style=
"color: #0000ff;"
></</span><span style=
"color: #800000;"
>p</span><span style=
"color: #0000ff;"
>></span>
<span style=
"color: #008080;"
> 78</span> <span style=
"color: #0000ff;"
><</span><span style=
"color: #800000;"
>p</span><span style=
"color: #0000ff;"
>></span>很简单,绝对定位,不加任何偏移量,用margin微调,完成!<span style=
"color: #0000ff;"
></</span><span style=
"color: #800000;"
>p</span><span style=
"color: #0000ff;"
>></span>
<span style=
"color: #008080;"
> 79</span> <span style=
"color: #0000ff;"
></</span><span style=
"color: #800000;"
>div</span><span style=
"color: #0000ff;"
>></span>
<span style=
"color: #008080;"
> 80</span> <span style=
"color: #0000ff;"
></</span><span style=
"color: #800000;"
>div</span><span style=
"color: #0000ff;"
>></span><span style=
"color: #008000;"
><!--</span><span style=
"color: #008000;"
>关闭wraper</span><span style=
"color: #008000;"
>--></span>
<span style=
"color: #008080;"
> 81</span> <span style=
"color: #0000ff;"
><</span><span style=
"color: #800000;"
>div </span><span style=
"color: #ff0000;"
>
class
</span><span style=
"color: #0000ff;"
>=
"wraper"
</span><span style=
"color: #0000ff;"
>></span>
<span style=
"color: #008080;"
> 82</span> <span style=
"color: #0000ff;"
><</span><span style=
"color: #800000;"
>div </span><span style=
"color: #ff0000;"
>
class
</span><span style=
"color: #0000ff;"
>=
"box box3"
</span><span style=
"color: #0000ff;"
>></span>
<span style=
"color: #008080;"
> 83</span> <span style=
"color: #0000ff;"
><</span><span style=
"color: #800000;"
>img </span><span style=
"color: #ff0000;"
>
class
</span><span style=
"color: #0000ff;"
>=
"absolute"
</span><span style=
"color: #ff0000;"
> src</span><span style=
"color: #0000ff;"
>=
"http://image.tianjimedia.com/uploadImages/2012/237/4134F4528419.jpg"
</span><span style=
"color: #ff0000;"
> alt</span><span style=
"color: #0000ff;"
>=
"A picture"
</span><span style=
"color: #ff0000;"
> style</span><span style=
"color: #0000ff;"
>=
"width:50px;height:30px"
</span> <span style=
"color: #0000ff;"
>/></span>
<span style=
"color: #008080;"
> 84</span> <span style=
"color: #0000ff;"
><</span><span style=
"color: #800000;"
>img </span><span style=
"color: #ff0000;"
>src</span><span style=
"color: #0000ff;"
>=
"http://imgsrc.baidu.com/forum/w%3D580/sign=0c101fe665380cd7e61ea2e59145ad14/f9a3492762d0f7032de1758a08fa513d2797c542.jpg"
</span><span style=
"color: #ff0000;"
> alt</span><span style=
"color: #0000ff;"
>=
"A picture"
</span><span style=
"color: #ff0000;"
> style</span><span style=
"color: #0000ff;"
>=
"width:100px;height:150px"
</span> <span style=
"color: #0000ff;"
>/></span>
<span style=
"color: #008080;"
> 85</span> <span style=
"color: #0000ff;"
><</span><span style=
"color: #800000;"
>img </span><span style=
"color: #ff0000;"
>src</span><span style=
"color: #0000ff;"
>=
"http://imgsrc.baidu.com/forum/w%3D580/sign=0c101fe665380cd7e61ea2e59145ad14/f9a3492762d0f7032de1758a08fa513d2797c542.jpg"
</span><span style=
"color: #ff0000;"
> alt</span><span style=
"color: #0000ff;"
>=
"A picture"
</span><span style=
"color: #ff0000;"
> style</span><span style=
"color: #0000ff;"
>=
"width:100px;height:150px"
</span> <span style=
"color: #0000ff;"
>/></span>
<span style=
"color: #008080;"
> 86</span> <span style=
"color: #0000ff;"
><</span><span style=
"color: #800000;"
>img </span><span style=
"color: #ff0000;"
>src</span><span style=
"color: #0000ff;"
>=
"http://imgsrc.baidu.com/forum/w%3D580/sign=0c101fe665380cd7e61ea2e59145ad14/f9a3492762d0f7032de1758a08fa513d2797c542.jpg"
</span><span style=
"color: #ff0000;"
> alt</span><span style=
"color: #0000ff;"
>=
"A picture"
</span><span style=
"color: #ff0000;"
> style</span><span style=
"color: #0000ff;"
>=
"width:100px;height:150px"
</span> <span style=
"color: #0000ff;"
>/></span>
<span style=
"color: #008080;"
> 87</span> <span style=
"color: #0000ff;"
><</span><span style=
"color: #800000;"
>p</span><span style=
"color: #0000ff;"
>></span>如果我们要将图像定位到黑色边框的右上角,应该怎么办?<span style=
"color: #0000ff;"
></</span><span style=
"color: #800000;"
>p</span><span style=
"color: #0000ff;"
>></span>
<span style=
"color: #008080;"
> 88</span> <span style=
"color: #0000ff;"
><</span><span style=
"color: #800000;"
>p</span><span style=
"color: #0000ff;"
>></span><span style=
"color: #000000;"
>第一种方法,像刚才那样,直接绝对定位,再用margin调整;
</span><span style=
"color: #008080;"
> 89</span> 这种方法需要消耗一点脑细胞,算一算到底应该位移多少像素。<span style=
"color: #0000ff;"
></</span><span style=
"color: #800000;"
>p</span><span style=
"color: #0000ff;"
>></span>
<span style=
"color: #008080;"
> 90</span> <span style=
"color: #0000ff;"
></</span><span style=
"color: #800000;"
>div</span><span style=
"color: #0000ff;"
>></span>
<span style=
"color: #008080;"
> 91</span> <span style=
"color: #0000ff;"
></</span><span style=
"color: #800000;"
>div</span><span style=
"color: #0000ff;"
>></span><span style=
"color: #008000;"
><!--</span><span style=
"color: #008000;"
>关闭wraper</span><span style=
"color: #008000;"
>--></span>
<span style=
"color: #008080;"
> 92</span> <span style=
"color: #0000ff;"
><</span><span style=
"color: #800000;"
>div </span><span style=
"color: #ff0000;"
>
class
</span><span style=
"color: #0000ff;"
>=
"wraper"
</span><span style=
"color: #0000ff;"
>></span>
<span style=
"color: #008080;"
> 93</span> <span style=
"color: #0000ff;"
><</span><span style=
"color: #800000;"
>div </span><span style=
"color: #ff0000;"
>
class
</span><span style=
"color: #0000ff;"
>=
"box box4"
</span><span style=
"color: #0000ff;"
>></span>
<span style=
"color: #008080;"
> 94</span> <span style=
"color: #0000ff;"
><</span><span style=
"color: #800000;"
>div </span><span style=
"color: #ff0000;"
>
class
</span><span style=
"color: #0000ff;"
>=
"relative"
</span><span style=
"color: #0000ff;"
>></span>
<span style=
"color: #008080;"
> 95</span> <span style=
"color: #0000ff;"
><</span><span style=
"color: #800000;"
>img </span><span style=
"color: #ff0000;"
>
class
</span><span style=
"color: #0000ff;"
>=
"absolute"
</span><span style=
"color: #ff0000;"
> src</span><span style=
"color: #0000ff;"
>=
"http://image.tianjimedia.com/uploadImages/2012/237/4134F4528419.jpg"
</span><span style=
"color: #ff0000;"
> alt</span><span style=
"color: #0000ff;"
>=
"A picture"
</span><span style=
"color: #ff0000;"
> style</span><span style=
"color: #0000ff;"
>=
"width:50px;height:30px"
</span> <span style=
"color: #0000ff;"
>/></span>
<span style=
"color: #008080;"
> 96</span> <span style=
"color: #0000ff;"
></</span><span style=
"color: #800000;"
>div</span><span style=
"color: #0000ff;"
>></span>
<span style=
"color: #008080;"
> 97</span> <span style=
"color: #0000ff;"
><</span><span style=
"color: #800000;"
>img </span><span style=
"color: #ff0000;"
>src</span><span style=
"color: #0000ff;"
>=
"http://imgsrc.baidu.com/forum/w%3D580/sign=0c101fe665380cd7e61ea2e59145ad14/f9a3492762d0f7032de1758a08fa513d2797c542.jpg"
</span><span style=
"color: #ff0000;"
> alt</span><span style=
"color: #0000ff;"
>=
"A picture"
</span><span style=
"color: #ff0000;"
> style</span><span style=
"color: #0000ff;"
>=
"width:100px;height:150px"
</span> <span style=
"color: #0000ff;"
>/></span>
<span style=
"color: #008080;"
> 98</span> <span style=
"color: #0000ff;"
><</span><span style=
"color: #800000;"
>img </span><span style=
"color: #ff0000;"
>src</span><span style=
"color: #0000ff;"
>=
"http://imgsrc.baidu.com/forum/w%3D580/sign=0c101fe665380cd7e61ea2e59145ad14/f9a3492762d0f7032de1758a08fa513d2797c542.jpg"
</span><span style=
"color: #ff0000;"
> alt</span><span style=
"color: #0000ff;"
>=
"A picture"
</span><span style=
"color: #ff0000;"
> style</span><span style=
"color: #0000ff;"
>=
"width:100px;height:150px"
</span> <span style=
"color: #0000ff;"
>/></span>
<span style=
"color: #008080;"
> 99</span> <span style=
"color: #0000ff;"
><</span><span style=
"color: #800000;"
>img </span><span style=
"color: #ff0000;"
>src</span><span style=
"color: #0000ff;"
>=
"http://imgsrc.baidu.com/forum/w%3D580/sign=0c101fe665380cd7e61ea2e59145ad14/f9a3492762d0f7032de1758a08fa513d2797c542.jpg"
</span><span style=
"color: #ff0000;"
> alt</span><span style=
"color: #0000ff;"
>=
"A picture"
</span><span style=
"color: #ff0000;"
> style</span><span style=
"color: #0000ff;"
>=
"width:100px;height:150px"
</span> <span style=
"color: #0000ff;"
>/></span>
<span style=
"color: #008080;"
>100</span> <span style=
"color: #0000ff;"
><</span><span style=
"color: #800000;"
>p</span><span style=
"color: #0000ff;"
>></span>第二种方法,就是大家喜闻乐见的relative+absolute定位啦。<span style=
"color: #0000ff;"
></</span><span style=
"color: #800000;"
>p</span><span style=
"color: #0000ff;"
>></span>
<span style=
"color: #008080;"
>101</span> <span style=
"color: #0000ff;"
><</span><span style=
"color: #800000;"
>p</span><span style=
"color: #0000ff;"
>></span>不过,看在absolute那么讨厌relative的面子上,relative就只欺负它一个就好了,千千万万不要影响到其它花花草草。<span style=
"color: #0000ff;"
></</span><span style=
"color: #800000;"
>p</span><span style=
"color: #0000ff;"
>></span>
<span style=
"color: #008080;"
>102</span> <span style=
"color: #0000ff;"
><</span><span style=
"color: #800000;"
>p</span><span style=
"color: #0000ff;"
>></span>具体来说,给这个需要定位的图像外加一层div,设置relative,让这个relative只影响需要绝对定位的元素。<span style=
"color: #0000ff;"
></</span><span style=
"color: #800000;"
>p</span><span style=
"color: #0000ff;"
>></span>
<span style=
"color: #008080;"
>103</span> <span style=
"color: #0000ff;"
><</span><span style=
"color: #800000;"
>p</span><span style=
"color: #0000ff;"
>></span>relative影响最小化!<span style=
"color: #0000ff;"
></</span><span style=
"color: #800000;"
>p</span><span style=
"color: #0000ff;"
>></span>
<span style=
"color: #008080;"
>104</span> <span style=
"color: #0000ff;"
></</span><span style=
"color: #800000;"
>div</span><span style=
"color: #0000ff;"
>></span>
<span style=
"color: #008080;"
>105</span> <span style=
"color: #0000ff;"
></</span><span style=
"color: #800000;"
>div</span><span style=
"color: #0000ff;"
>></span><span style=
"color: #008000;"
><!--</span><span style=
"color: #008000;"
>关闭wraper</span><span style=
"color: #008000;"
>--></span>
<span style=
"color: #008080;"
>106</span> <span style=
"color: #0000ff;"
></</span><span style=
"color: #800000;"
>body</span><span style=
"color: #0000ff;"
>></span>
<span style=
"color: #008080;"
>107</span> <span style=
"color: #0000ff;"
></</span><span style=
"color: #800000;"
>html</span><span style=
"color: #0000ff;"
>></span>