zoukankan      html  css  js  c++  java
  • 样式操作案例5-改变box的大小和位置

    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <title>Document</title>
      <style>
        #box {
           100px;
          height: 100px;
          background-color: pink;
        }
    
        .cls {
           200px;
          height: 200px;
          position: absolute;
          top: 100px;
          left: 100px;
          background-color: pink;
        }
      </style>
    </head>
    <body>
      <input type="button" value=" 点我 " id="btn">
      <br>
      <div id="box"></div>
      
      <script src="common.js"></script>
      <script>
        my$('btn').onclick = function () {
          var box = my$('box');
          // 改变box的大小和位置
          // 使用class
          // box.className = 'cls';
          // 
          // 使用style  设置大小和位置的时候 数字必须带单位
          box.style.width = '200px';
          box.style.height = '200px';
    
          box.style.position = 'absolute';
          box.style.left = '200px';
          box.style.top = '200px';
    
          console.log(box.style);
        }
    
      </script>
    </body>
    </html>

    common中的代码

    function my$(id) {
      return document.getElementById(id);
    }
  • 相关阅读:
    寒假作业:第三次作业
    markdown笔记
    c#基类继承
    atom插件安装
    git命令
    vue2.3时使用手机调试,提示媒体已断开的解决方案
    vue中使用hotcss--stylus
    JS调试工具
    Facebook的bigpipe
    xss--攻击方式
  • 原文地址:https://www.cnblogs.com/jiumen/p/11405079.html
Copyright © 2011-2022 走看看