日期:2014-05-16 浏览次数:20281 次
<!DOCTYPE HTML> <html> <head> <meta charset="gb2312" /> <title></title> <style> div { position:absolute; left:100px; right:0; top:100px; bottom:0; width:100px; height:100px; border:1px solid red; } </style> </head> <body> <div id="test"></div> </body> </html>
------解决方案--------------------
<!doctype html> <html> <head> <meta charset="utf-8"/> <script src="jquery.js"></script> <style> div{ border: 1px solid black; width: 600px; height: 400px; position: relative; } canvas{ border: 1px solid red; } </style> </head> <body> <div> <canvas width="300" height="200"></canvas> </div> <p>dasfjasdflkasjdf</p> <script> var canvas = $('canvas'); canvas.css({ position: "absolute", right: "20px", bottom: "10px" }); var pos = canvas.position(); alert(pos.left); // 278=600-300-20-1*2 alert(pos.top); // 188=400-200-10-1*2 alert(canvas.css("left")) // auto alert(canvas.css("top")) // auto alert(canvas.css("right")) // 20px alert(canvas.css("bottom")) // 10px </script> </body> </html>