一篇弄懂 clientWidth、clientHeight、clientLeft、clientTop的区别!(3)

快速理解client之间的区别

简介

  1.clientHeight/clientWidth 属性是一个只读属性,它返回该元素的像素高度/宽度,高度/宽度 包含内边距(padding),不包含边框(border),外边距(margin)和滚动条,是一个整数,单位是像素 px。
  2.clientTop/clientLeft 属性是一个只读属性,表示一个元素的顶部边框/左边框 的宽度,以像素表示。不包括外边距和内边距。

完整代码

以下代码均在Chrome浏览器中测试

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
       .div{
           width: 300px;
           height: 300px;
           padding: 13px;
           margin: 17px;
           border: 11px teal solid;
           background-color: wheat;
       }
        #btn{
            width: 50px;
            height: 50px;
        }
    </style>
</head>
<body>
    <div class="div"></div>
    <button id="btn">点我</button>
</body>
<script>
    let div = document.getElementsByTagName('div')[0]
    btn.onclick=function(){
        // .div(height/width:300 + padding:13*2) == 326
        console.log('clientHeight',div.clientHeight);
        console.log('clientWidth',div.clientWidth);
        // .div(border:11)
        console.log('clientTop',div.clientTop);
        console.log('clientLeft',div.clientLeft);
    }
</script>
</html>

  效果如下:
在这里插入图片描述
  client(可视区域)相对于offset,scroll来说,比较好理解。

总结

下面将offset、scroll、client的关系以图形的方式来展示:
请添加图片描述
相关文章:
链接: 一篇弄懂 offsetWidth、offsetHeight、offsetleft、offsetTop和offsetParent的区别!(1).
链接: 一篇弄懂 scrollWidth、scrollHeight、scrollLeft和scrollTop的区别!(2).

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
20200420使用VB6.0求33选6的全组合数(解决变长字符串超过1MB之后写入的问题) 最近需要求组合数(买双色球生成号码用^_) 以前在大学专门学习过VB6.0,今后会迁移到VC6.0。 预计会在2020.5.1强化一下MFC,就可以了! 我也不知道边长字符串到底写入多少回崩溃。(现阶段人也不年轻了,也没有这么多时间去研究了!有兴趣的同学跟帖告诉我一下,在此谢过了!) ​ VERSION 5.00 Begin VB.Form Form1 Caption = "Form1" ClientHeight = 12825 ClientLeft = 450 ClientTop = 615 ClientWidth = 14535 LinkTopic = "Form1" ScaleHeight = 12825 ScaleWidth = 14535 Begin VB.TextBox Text2 BeginProperty Font Name = "宋体" Size = 14.25 Charset = 134 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 12255 Left = 600 MultiLine = -1 'True ScrollBars = 3 'Both TabIndex = 1 Top = 360 Width = 6135 End Begin VB.CommandButton Command2 Caption = "求33选6的全组合数" BeginProperty Font Name = "宋体" Size = 26.25 Charset = 134 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 975 Left = 8040 TabIndex = 0 Top = 5520 Width = 4935 End End Attribute VB_Name = "Form1" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Option Explicit Private Sub Command1_Click() End Sub Private Sub Command2_Click() Dim h1%, h2%, h3%, h4%, h5%, h6% Dim h6sum% Dim i% Dim j% Dim temp% Dim count% Dim guangyayuan(35) As Integer Dim wutongshan(35) As Integer Dim guangyayuan6(35) As Integer Dim hong1%, hong2%, hong3%, hong4%, hong5%, hong6% Dim strWj As String ' For hong1 = 1 To 10 ' 'For hong2 = hong1 To 11 ' For hong2 = hong1 + 1 To 11 ' For hong3 = hong2 + 1 To 12 ' For hong4 = hong3 + 1 To 13 ' For hong5 = hong4 + 1 To 14 ' For hong6 = hong5 + 1 To 15 For hong1 = 1 To 28 For hong2 = hong1 + 1 To 29 For hong3 = hong2 + 1 To 30 For hong4 = hong3 + 1 To 31 For hong5 = hong4 + 1 To 32 For hong6 = hong5 + 1 To 33 'Text2 = Text2 & hong1 & "," & hong2 & "," & hong3 & "," & hong4 & "," & hong5 & "," & hong6 & vbCrLf strWj = strWj & hong1 & "," & hong2 & "," & hong3 & "," & hong4 & "," & hong5 & "," & hong6 & vbCrLf Next hong6 Next hong5 Next hong4 Next hong3 Next hong2 Next hong1 'Close #2 'Open "d:\ScoreW2.txt" For Output As #1 'Open "d:\求12选3的全组合数.txt" For Output As #1 Open "d:\求33选6的全组合数.txt" For Output As #1 'Write #1, Text2 Write #1, strWj Close #1 End Sub 我这里采用了一个最简单粗暴的做法,将每一组的六个号码立即写入磁盘。(具体交给操作系统了) 求33选6的全组合数.txt 大概23MB。 大致内容: "1,2,3,4,5,6 " "1,2,3,4,5,7 " "1,2,3,4,5,8 " "1,2,3,4,5,9 " "1,2,3,4,5,10 " "1,2,3,4,5,11 " "1,2,3,4,5,12 " "1,2,3,4,5,13 " "1,2,3,4,5,14 " "1,2,3,4,5,15 " "1,2,3,4,5,16 " "1,2,3,4,5,17 " "1,2,3,4,5,18 " "1,2,3,4,5,19 " "1,2,3,4,5,20 " "1,2,3,4,5,21 " "1,2,3,4,5,22 " "1,2,3,4,5,23 " "1,2,3,4,5,24 " "1,2,3,4,5,25 " "1,2,3,4,5,26 …… " "25,28,30,31,32,33 " "25,29,30,31,32,33 " "26,27,28,29,30,31 " "26,27,28,29,30,32 " "26,27,28,29,30,33 " "26,27,28,29,31,32 " "26,27,28,29,31,33 " "26,27,28,29,32,33 " "26,27,28,30,31,32 " "26,27,28,30,31,33 " "26,27,28,30,32,33 " "26,27,28,31,32,33 " "26,27,29,30,31,32 " "26,27,29,30,31,33 " "26,27,29,30,32,33 " "26,27,29,31,32,33 " "26,27,30,31,32,33 " "26,28,29,30,31,32 " "26,28,29,30,31,33 " "26,28,29,30,32,33 " "26,28,29,31,32,33 " "26,28,30,31,32,33 " "26,29,30,31,32,33 " "27,28,29,30,31,32 " "27,28,29,30,31,33 " "27,28,29,30,32,33 " "27,28,29,31,32,33 " "27,28,30,31,32,33 " "27,29,30,31,32,33 " "28,29,30,31,32,33 " 读者可能很容易看到会多一个英文的引号,这个怎么解决呢? https://zhidao.baidu.com/question/7939187.html 用vb读写文件时,写成的文本文件每行都有双引号,怎么才能把双引号去掉啊? 怎样写的文件,才能没有双引号啊? wangtk1982 2006-05-30 使用print语句 不用用write 本回答由提问者推荐 3 评论(1) 分享 举报 monkywin 2006-05-30 用print写入文件。 用input读取文本。 修正之后: VERSION 5.00 Begin VB.Form Form1 Caption = "Form1" ClientHeight = 12825 ClientLeft = 450 ClientTop = 615 ClientWidth = 14535 LinkTopic = "Form1" ScaleHeight = 12825 ScaleWidth = 14535 Begin VB.TextBox Text2 BeginProperty Font Name = "宋体"

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值