美文网首页
clientHeight、clientwidth、clientt

clientHeight、clientwidth、clientt

作者: daisx | 来源:发表于2017-05-04 11:12 被阅读0次
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
        <style>
            * {  margin: 0;  padding: 0;border:none; }
            body{    height:100%}
            #box{ width: 100px; height: 100px; border: 30px solid red;
                padding: 20px;   position: relative;}
            #box1{   height: 100px;width: 100px;
                background: blue;position: absolute;left: 10px;top:10px;
                padding: 10px;border:1px solid black; }
        </style>
    </head>
    <body>
    <div id="box">
        <div id="box1">
            <p>offset相关测试</p>
            <p>offset相关测试</p>
            <p>offset相关测试</p>
            <p>offset相关测试</p>
            <p>offset相关测试</p>
            <p>offset相关测试</p>
            <p>offset相关测试</p>
            <p>offset相关测试</p>
            <p>offset相关测试</p>
            <p>offset相关测试</p>
            <p>offset相关测试</p>
            <p>offset相关测试</p>
            <p>offset相关测试</p>
            <p>offset相关测试</p>
            <p>offset相关测试</p>
            <p>offset相关测试</p>
        </div>
    </div>
    <script>
        window.onload = function () {
            console.log('-------------------------------');
            console.log(box.clientHeight);//140
            console.log(box.clientWidth);//140
            console.log(box.clientLeft);//30
            console.log(box.clientTop);//30
            console.log('-------------------------------');
            console.log(box1.clientHeight);//120
            console.log(box1.clientWidth);//120
            console.log(box1.clientLeft);//1
            console.log(box1.clientTop);//1
        }
    </script>
    </body>
    </html>
    

    clientHeight = height +(top) padding + (bottom)padding

    clientWidth = Width + (left)padding + (right)padding

    clientLeft = 当前元素的left-border宽度

    clientTop = 当前元素的top-border宽度

    相关文章

      网友评论

          本文标题:clientHeight、clientwidth、clientt

          本文链接:https://www.haomeiwen.com/subject/tpurtxtx.html