mxs___ 2021-08-27 11:58 采纳率: 78.6%
浏览 24
已结题

盒子居中了但调试工具里的数据显示左右距离不一样

请教各位 我这个图片里边的 position是啥 为啥盒子居中了但是图片上左右距离不一样

img


  a {
            display: block;
            font-size: 35px;
            width: 100%;
            text-align: center;
        }
        .touming {
            display: none;
            width: 100%;
            height: 100%;
            background-color: rgba(0,0,0,.3);
            position: fixed;
            top: 0;
            left: 0;
        }
        .box {
            display: none;
            position: absolute;
            width: 500px;
            height: 300px;
            background-color: #fff;
            z-index: 3;
            top: 50%;
            left: 50%;
           margin-top: -150px;
           margin-left: -250px;
            filter: drop-shadow(0 0 3px #333);
        }
        h1 {
            position: relative;
            cursor: move;
        }
        h1 a {
            position: absolute;
            top: -43px;
            right: -23px;
            text-align: center;
            line-height: 50px;
            font-size: 14px;
            text-decoration: none;
            color: #000;
            width: 50px;
            height: 50px;
            border-radius: 100%;
            background-color: #fff;
        }
    </style>
</head>
<body>
    <a class="click" href="javascript:;">点击弹出登录框</a>
    <div class="box">
        <h1>登录会员<a class="close-btn" href="javascript:;">关闭</a></h1>
        <div>&emsp;用户名:<input type="text"></div>
        <div>登录密码:<input type="text"></div>
        <button>登录会员</button>
    </div>
    <div class="touming"></div>

    <script>
        var click = document.querySelector('.click');
        var touming = document.querySelector('.touming');
        var box = document.querySelector('.box');
        var h1 = document.querySelector('h1');
        click.addEventListener('click',function () {
            touming.style.display = 'block';
            box.style.display = 'block';
        })
        var close = document.querySelector('.close-btn');
        close.addEventListener('click',function () {
            touming.style.display = 'none';
            box.style.display = 'none';
        })
        h1.addEventListener('mousedown',function () {
            console.log(box.offsetLeft);
            console.log(event.pageX);
            var x = event.clientX - box.offsetLeft;
            var y = event.clientY - box.offsetTop;
            // console.log(x,y);
        })
    </script>
  • 写回答

1条回答 默认 最新

  • zlebhs 2021-08-27 12:23
    关注

    674.5-250难道不等于424.5?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 9月4日
  • 已采纳回答 8月27日
  • 创建了问题 8月27日

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。