美文网首页
outerWidth、innerWidth、width

outerWidth、innerWidth、width

作者: YoungEvita | 来源:发表于2018-07-27 07:51 被阅读0次

定义

  • width() - 设置或返回元素的宽度
  • height()- 设置或返回元素的高度
  • innerWidth() - 返回元素的宽度+ padding
  • innerHeight() - 返回元素的高度+ padding
  • outerWidth() - 返回元素的宽度+ padding + border,当参数为true时,+ margin
  • outerHeight()- 返回元素的高度+ padding + border ,当参数为true时,+ margin

示例

<html>

<head lang="en">
    <meta charset="UTF-8">
    <title>demo</title>
    <script type="text/javascript" src="jquery-1.7.2.min.js"></script>
    <style>
        .box {
            background: red;
            width: 100px;
            height: 100px;
            border: 1px solid gray;
            margin: 5px;
            padding: 10px;
        }
    </style>
</head>

<body>
    <div class="box" id="boxId">
    </div>
</body>

</html>
<script type="text/javascript">

    console.log('width: ' + $("#boxId").width());
    console.log('height: ' + $("#boxId").height());

    console.log('innerWidth: ' + $('#boxId').innerWidth());
    console.log('innerHeigth: ' + $('#boxId').innerHeight());

    console.log('outerWidth: ' + $('#boxId').outerWidth());
    console.log('outerHeigth: ' + $('#boxId').outerHeight());

    console.log('outerWidth-true: ' + $('#boxId').outerWidth(true));
    console.log('outerHeigth-true: ' + $('#boxId').outerHeight(true));
</script>
盒子模型图盒子模型图 输出结果输出结果

相关文章

网友评论

      本文标题:outerWidth、innerWidth、width

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