CSS盒模型是比较复杂的,尤其是当页面中有滚动条时,仅仅通过css来操作高度宽度是不够的,幸运的是Javascript提供了不少这样的接口。Javascript中clientHeight / cliengWidth, scrollHeight /scrollWidth, offsetHeight / offsetWidth, height / width 都可以获取高度和宽度,但是他们有一些细微的差别:

  • offsetHeight / offsetWidth:文档整体区域包含滚动条和border,对于display:block的元素通过width/height + padding + border可以计算出来。
  • clientHeight / cliengWidth:可见区域包含padding,不包含border和滚动条,不能通过CSS样式计算出来,取决于滚动条的大小。
  • scrollHeight / scrollWidth:内容区域的大小,不包含border,包含不在可见区域内的隐藏部分,不能通过CSS样式计算出来。
  • height / width:不包含borderpadding

另外:滚动条的宽度可以通过如下方式计算:

scrollbarWidth = offsetWidth - clientWidth - getComputedStyle().borderLeftWidth - getComputedStyle().borderRightWidth  

各种height/width总结的更多相关文章

  1. jQuery - 03. each、prevaAll、nextAll、获取属性、修改属性attr/val/text()、jq.height/width、offset()./position()./scrol Left/Top 、事件绑定bind、delegate、on、事件解绑、事件对象、多库共存

    each 方法 $ ( selector).each(function( index,element) {  } );   参数一表示当前元素在所有匹配元素中的索引号 参数二表示当前元素(DOM对象) ...

  2. Expanded, SingleChildScrollView, CustomScrollView, container, height, width

    SingleChildScrollView, CustomScrollView, container, init: double.inifinity. then use Expanded to con ...

  3. 父容器的flowover:hidden 必须配合父容器的宽高height width才能生效

    有时候 给父容器 加上了 flowover:hidden 这个css后, 其中的子元素为什么仍然会跑出来? 解决的根本方法就是要给 父容器 加上具体的一个宽度, 或高度. (而这个宽度和高度, 其实你 ...

  4. jQueryEasyUI中DataGrid的height,width,fit,fitColumns属性

    height: 600, //不指定则默认垂直包裹,指定了则固定 width:1200,//不指定则水平100%平铺,指定了则固定 fit:false,//true:高度填充父窗体,忽略height属 ...

  5. IOS UI Frame 相对位置调整 与优化方法 Height Width X Y 调整

    不使用xib ,纯代码开发的过程中,动态UI  需要改对象的大小位置 反复使用CGRectMake 去 setFrame  非常低效耗时,而且 牵一发动全身. 以下整理出几个方法,方便动态布局 1.s ...

  6. css中height, width默认值

    转载自:https://www.cnblogs.com/heyode/p/5973960.html <body> <div class="wrap"> &l ...

  7. html元素height(width)是怎么确定的?

    1.若height是确定的(比如height:100px),则height直接可确定(还受min-height,max-height影响,见height,min-height,max-heigth的作 ...

  8. Opencv中图像height width X 轴 Y轴 rows cols之间的对应关系

    这里做一个备忘录:

  9. [WPF系列]- Style - Specify width/height as resource in WPF

    <Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:sys=" ...

随机推荐

  1. iOS9 视频播放

       self.videoFileURL = [NSURL URLWithString:[NSString stringWithFormat:@"file:///%@", self ...

  2. Linux umask权限

    文件基本权限 Linux中文件权限由三部分组成: rw-r--r-- 前三位:表示用户所拥有的权限 中三位:表示用户所在组的权限 后三们:表示其他用户的权限 权限 八进制 十进制 - - - 000 ...

  3. 利用ROW_NUMBER中的partition by 删除重复Key的数据

    With temp As ( Select ROW_NUMBER() over(partition by LogisticsPlan order by createon) rowID,ID from ...

  4. [记]Centos下流量统计使用记录

    因为最近要进行centos流量统计,需求是想针对tomcat进行针对性的上下行流量时段统计及汇总,找了很多资料及命令,要么是可以针对进程的但是没有汇总,要么是有汇总但是不针对进程. 所以只能混合几个命 ...

  5. Default style sheet for HTML 4

    http://www.w3.org/TR/CSS21/sample.html html, address, blockquote, body, dd, div, dl, dt, fieldset, f ...

  6. Linux socat轻松实现TCP/UDP端口转发

    1.TCP端口转发 socat -d TCP4-LISTEN:,reuseaddr,fork TCP4: 2.UDP端口转发 socat -T UDP4-LISTEN:,reuseaddr,fork ...

  7. ansible常用ad hoc操作

    ansible group001 -i hosts.ip -m shell -a -v

  8. Easy前端正确删除datagrid的方式(避免直接删除索引没更新问题)

    在删除传参时,不要传索引来删除行 columns: [[ { title: '代码', field: 'Code', width: 100 }, { title: '名称', field: 'Name ...

  9. JavaScript 对象属性

    JavaScript 对象属性 属性中的 . 和 [ ](点 和 方括号)的区别 .  :取对象自身的属性值: [ ]:括号内容可以是变量: var obj = {}; obj.name = 'Twx ...

  10. ASP.NET Core使用Ping判断网络是否接通

    static void Main(string[] args) { // 主机地址 string targetHost = "bing.com"; string data = &q ...