日期:2014-05-17 浏览次数:20789 次
<html> <head> <style type="text/css"> #container { position: absolute; top: 50px; left: 50px; width: 600px; height: 500px; border: 5px solid black; background: white; } #child { float: left; width: 200px; height: 100%; border: 5px solid red; background: green; } </style> </head> <body> <div id="container"> <div id="child"></div> </div> </body> </html>
<!DOCTYPE HTML> <html> <head> <meta charset="gb2312" /> <title></title> <style> </style> </head> <body> <button id="btn">弹出层</button> <script> function $(o){return document.getElementById(o)} var css = function(obj, attr, value){ switch(arguments.length){ case 2: //二个参数, 如果第二个参数是对象, 批量设置属性 if(typeof attr == 'object'){ for(var i in attr){ obj.style[i] = attr[i]; } } //二个参数, 如果第二个参数是字符串, 读取属性值 else{ return obj.currentStyle? obj.currentStyle[attr] : getComputedStyle(obj, null)[attr]; } break; case 3: //三个参数, 单一设置属性 obj.style[attr] = value; break; default: alert('参数有误!'); } } var o = $('btn'); alert( css(o, 'fontSize') ) css(o, { fontSize: 123+'px', color: 'red' }) </script> </body> </html>