<body> <h3>原始</h3> <div class="baseCls leftFloat">div1</div> <div class="baseCls leftFloat">div2</div> <div class="baseCls leftFloat">div3</div> <div class="baseCls leftFloat">div4</div> <br/><br/><br/><br/><br/><br/> <hr/> <h3>向左移动</h3> <div class="baseCls leftFloat">div1</div> <div class="baseCls leftFloat moveLeft">div2</div> <div class="baseCls leftFloat">div3</div> <div class="baseCls leftFloat">div4</div> <br/><br/><br/><br/><br/><br/> <hr/> <h3>向右移动</h3> <div class="baseCls leftFloat">div1</div> <div class="baseCls leftFloat moveRight">div2</div> <div class="baseCls leftFloat">div3</div> <div class="baseCls leftFloat">div4</div> <br/><br/><br/><br/><br/><br/> <hr/> <h3>向上移动</h3> <div class="baseCls leftFloat">div1</div> <div class="baseCls leftFloat moveTop">div2</div> <div class="baseCls leftFloat">div3</div> <div class="baseCls leftFloat">div4</div> <br/><br/><br/><br/><br/><br/> <hr/> <h3>向下移动</h3> <div class="baseCls leftFloat">div1</div> <div class="baseCls leftFloat">div2</div> <div class="baseCls leftFloat moveBottom">div3</div> <div class="baseCls leftFloat">div4</div> </body>
<style type="text/css"> body { margin-left: 100px; margin-top: 100px; border: 1px solid gray; } .baseCls { border: 1px solid black; width: 100px; height: 100px; background-color: gray; margin-left: 10px; margin-top: 10px; } .leftFloat { float : left; } /* position - relative 以原来位置的左上角为参考点 */ .moveLeft,.moveRight,.moveTop,.moveBottom { position: relative; } /* 以原来位置的左上角为参考点, 左移 50px. */ .moveLeft { left: -50px; background-color: red; } /* 以原来位置的左上角为参考点, 右移 50px. */ .moveRight { left: 50px; background-color: red; } /* 以原来位置的左上角为参考点, 上移 50px. */ .moveTop { top: -50px; background-color: red; } /* 以原来位置的左上角为参考点, 下移 50px. */ .moveBottom { top: 50px; background-color: red; } </style>
<body> <div class="baseCls leftFloat">div1</div> <div class="baseCls leftFloat absMove">div2</div> <div class="baseCls leftFloat">div3</div> <div class="baseCls leftFloat">div4</div> </body>
<style type="text/css"> body { border: 1px solid gray; } .baseCls { border: 1px solid black; width: 100px; height: 100px; background-color: gray; margin-left: 10px; margin-top: 10px; } .leftFloat { float : left; } /*以body左上角为参照点*/ .absMove { position: absolute; top: 100px; left: 50px; background-color: red; } </style>
<body> <div class="baseCls leftFloat">div1</div> <div class="baseCls leftFloat">div3</div> <div class="baseCls leftFloat">div4</div> <div class="specCls leftFloat"> <div class="baseCls leftFloat absMove">div2</div> </div> </body>
<style type="text/css"> body { border: 1px solid gray; } .baseCls { border: 1px solid black; width: 100px; height: 100px; background-color: gray; margin-left: 10px; } .leftFloat { float : left; } .absMove { position: absolute; top: 200px; left: 50px; background-color: red; } /*以div5为参考点*/ .specCls { border: 1px solid black; width: 400px; height: 200px; background-color: green; position: relative; left: 80px; /*改变div5的位置, div2跟着联动*/ top: 100px; } </style>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>postion-relative</title> <meta http-equiv="content-type" content="text/html;charset=utf-8"/> <style type="text/css"> body { margin-left: 100px; margin-top: 100px; border: 1px solid gray; } .baseCls { border: 1px solid black; width: 100px; height: 100px; background-color: gray; margin-left: 10px; margin-top: 10px; } .leftFloat { float : left; } /* position - relative 以原来位置的左上角为参考点 */ .moveLeft,.moveRight,.moveTop,.moveBottom { position: relative; } /* 以原来位置的左上角为参考点, 左移 50px. */ .moveLeft { left: -50px; background-color: red; } /* 以原来位置的左上角为参考点, 右移 50px. */ .moveRight { left: 50px; background-color: red; } /* 以原来位置的左上角为参考点, 上移 50px. */ .moveTop { top: -50px; background-color: red; } /* 以原来位置的左上角为参考点, 下移 50px. */ .moveBottom { top: 50px; background-color: red; } </style> </head> <body> <h3>原始</h3> <div class="baseCls leftFloat">div1</div> <div class="baseCls leftFloat">div2</div> <div class="baseCls leftFloat">div3</div> <div class="baseCls leftFloat">div4</div> <br/><br/><br/><br/><br/><br/> <hr/> <h3>向左移动</h3> <div class="baseCls leftFloat">div1</div> <div class="baseCls leftFloat moveLeft">div2</div> <div class="baseCls leftFloat">div3</div> <div class="baseCls leftFloat">div4</div> <br/><br/><br/><br/><br/><br/> <hr/> <h3>向右移动</h3> <div class="baseCls leftFloat">div1</div> <div class="baseCls leftFloat moveRight">div2</div> <div class="baseCls leftFloat">div3</div> <div class="baseCls leftFloat">div4</div> <br/><br/><br/><br/><br/><br/> <hr/> <h3>向上移动</h3> <div class="baseCls leftFloat">div1</div> <div class="baseCls leftFloat moveTop">div2</div> <div class="baseCls leftFloat">div3</div> <div class="baseCls leftFloat">div4</div> <br/><br/><br/><br/><br/><br/> <hr/> <h3>向下移动</h3> <div class="baseCls leftFloat">div1</div> <div class="baseCls leftFloat">div2</div> <div class="baseCls leftFloat moveBottom">div3</div> <div class="baseCls leftFloat">div4</div> </body> </html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>postion-absolute</title> <meta http-equiv="content-type" content="text/html;charset=utf-8"/> <style type="text/css"> body { border: 1px solid gray; } .baseCls { border: 1px solid black; width: 100px; height: 100px; background-color: gray; margin-left: 10px; margin-top: 10px; } .leftFloat { float : left; } /*以body左上角为参照点*/ .absMove { position: absolute; top: 100px; left: 50px; background-color: red; } </style> </head> <body> <div class="baseCls leftFloat">div1</div> <div class="baseCls leftFloat absMove">div2</div> <div class="baseCls leftFloat">div3</div> <div class="baseCls leftFloat">div4</div> </body> </html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>postion-absolute2</title> <meta http-equiv="content-type" content="text/html;charset=utf-8"/> <style type="text/css"> body { border: 1px solid gray; } .baseCls { border: 1px solid black; width: 100px; height: 100px; background-color: gray; margin-left: 10px; } .leftFloat { float : left; } .absMove { position: absolute; top: 200px; left: 50px; background-color: red; } /*以div5为参考点*/ .specCls { border: 1px solid black; width: 400px; height: 200px; background-color: green; position: relative; left: 80px; /*改变div5的位置, div2跟着联动*/ top: 100px; } </style> </head> <body> <div class="baseCls leftFloat">div1</div> <div class="baseCls leftFloat">div3</div> <div class="baseCls leftFloat">div4</div> <div class="specCls leftFloat"> <div class="baseCls leftFloat absMove">div2</div> </div> </body> </html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>postion-absolute2</title> <meta http-equiv="content-type" content="text/html;charset=utf-8"/> <style type="text/css"> body { border: 1px solid gray; } .baseCls { border: 1px solid black; width: 100px; height: 100px; background-color: gray; margin-left: 10px; } .leftFloat { float : left; } .fixed { position: fixed; top: 200px; left: 50px; background-color: red; } /*以div5为参考点*/ .specCls { border: 1px solid black; width: 400px; height: 200px; background-color: green; position: relative; left: 80px; /*改变div5的位置, div2跟着联动*/ top: 100px; } </style> </head> <body> <div class="baseCls leftFloat">div1</div> <div class="baseCls leftFloat">div3</div> <div class="baseCls leftFloat">div4</div> <div class="specCls leftFloat"> <div class="baseCls leftFloat fixed">div2</div> </div> </body> </html>