jQuery的width()、innerWidth()、outerWidth()方法
width():
不包括元素的外边距(margin)、内边距(padding)、边框(border)等部分的宽度。
innerWidth():
包括元素的内边距(padding),但不包括外边距(margin)、边框(border)等部分的宽度。
outerWidth():
包括元素的内边距(padding)、边框(border),但不包括外边距(margin)部分的宽度。你也可以指定参数为true,以包括外边距(margin)部分的宽度。
<body>
<div class="box"></div>
</body>
<style>
.box{ width: 100px;height: 100px;background-color: red; }
</style>
<script>
$(function () {
//无边距
console.log("width",$(".box").width());//100px
console.log("innerWid", $(".box").innerWidth());//100px
console.log("outerWid",$(".box").outerWidth());//100px
//加padding 10px;
$(".box").css("padding", "10px");
console.log("width", $(".box").width());//100px
console.log("innerWid", $(".box").innerWidth());//120px
console.log("outerWid", $(".box").outerWidth());//120px
//加border 5px
$(".box").css("border", "5px solid orange");
console.log("width", $(".box").width());//100px
console.log("innerWid", $(".box").innerWidth());//120px
console.log("outerWid", $(".box").outerWidth());//130px
//加margin 10px
$(".box").css("margin", "10px");
console.log("width", $(".box").width());//100px
console.log("innerWid", $(".box").innerWidth());//120px
console.log("outerWid", $(".box").outerWidth());//130px
console.log("outerWid", $(".box").outerWidth(true));//150px
})
</script>
jQuery的width()、innerWidth()、outerWidth()方法的更多相关文章
- jQuery中【width(),innerWidth(),outerWidth()】
这个问题,已经别扭我多年了,今天终于彻底解决了,拿出来庆贺一下.jquery作为开源项目,无论从思路上,还是从严谨性上,让人崇敬. 随着时间的流逝,jquery的一些功能被逐渐挖掘出来.通过jQuer ...
- jQuery—一些常见方法(3)【width(),innerWidth(),outerWidth()】
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- jquery width(), innerWidth(), outerWidth() 区别
#div1 { width: 100px; height: 100px; border: 5px black solid; padding: 10px; margin: 10px; backgroun ...
- jQuery中的width() innerWidth() outerWidth() outerWidth(true)的区别
width()仅仅包括content(内容) innerWidth()包括content(内容)和padding(补白) outerWidth()包括content(内容),padding(补白)和b ...
- jQuery height() innerHeight() outerHight() width() innerWidth() outerWidth()源码解读
在第二层each,传入的对象以height举例是这样的,{padding:innerHeight,content:height,"":outerHeight} 对它遍历调用func ...
- width() innerwidth() outerwidth() css('width')
不多说,用一图足以说明 首先先解释下普通元素和非普通元素, 非普通元素是指window,document这些 元素对象, 普通元素是指除window,document之外的元素,如:div 对于普通的 ...
- innerWidth outerWidth
在jQuery中: 一.width()方法用于获得元素宽度: 二.innerWidth()方法用于获得包括内边界(padding)的元素宽度; 三.outerWidth()方法用于获得包括内边界(pa ...
- JQuery中width和JS中JS中关于clientWidth offsetWidth scrollWidth 等的含义
JQuery中: width()方法用于获得元素宽度: innerWidth()方法用于获得包括内边界(padding)的元素宽度: outerWidth()方法用于获得包括内边界(padding)和 ...
- jQuery中width、innerWidth、outerWidth的区别
原文:摘自http://www.canaansky.com/blog/107/ 在css的盒子模型中,最内部是content area,然后是padding.border.margin 那么width ...
- width() 、 height() 方法;innerWidth() 、innerHeight() 方法;outerWidth() 、 outerHeight() 方法的区别
1.width() . height() 方法 设置或返回元素的宽度.高度(不包括内边距.边框或外边距): 2.innerWidth() .innerHeight() 方法 返回元素的宽度.高度(包括 ...
随机推荐
- SAP 后台job
SAP 如何定义后台job 有两种方 1是se38执行可执行程序后,菜单栏‘程序’--->'后台执行',输入输出设备,ENTER两次后,选择开始时间(立刻执行,或定义日期时间,也可周期执行..) ...
- Linux启动应用(比如jmeter)报An error occurred: Can't connect to X11 window server using ':0.0' as the value of the DISPLAY variable.
Linux启动应用(比如jmeter)报An error occurred: Can't connect to X11 window server using ':0.0' as the value ...
- beego——ORM使用方法
先来看一个简单示例: models.gp package main import ( "github.com/astaxie/beego/orm" ) type User stru ...
- datetime时间处理
基本数据获取: In [38]: import datetime as dt In [39]: on = dt.datetime.now() #获取当前准确时间 In [40]: on Out[40] ...
- python全栈开发从入门到放弃之列表的内置方法
1.列表切片 l=['a','b','c','d','e','f'] print(l[1:5]) # 根据索引号来切片,但顾头不顾尾 ['b', 'c', 'd', 'e'] print(l[1:5: ...
- maven打包生成war
- vue-cli的utils.js文件详解
转载自:http://www.cnblogs.com/ye-hcj/p/7078047.html utils.js文件 // 引入nodejs路径模块var path = require('path' ...
- Hadoop中RPC协议小例子报错java.lang.reflect.UndeclaredThrowableException解决方法
最近在学习传智播客吴超老师的Hadoop视频,里面他在讲解RPC通信原理的过程中给了一个RPC的小例子,但是自己编写的过程中遇到一个小错误,整理如下: log4j:WARN No appenders ...
- Entity FrameWork Code First 之Model分离
之前一直用DB First新建类库进行使用,最近开始研究Code First.Code First也可以将Model新建在类库里面,然后通过数据迁移等操作生成数据库. 现在说下主要步骤: 1.新建类库 ...
- JavaScript返回顶部特效
样式: <style type="text/css"> /*返回顶部特效*/ a { border: none; text-decoration: none; outl ...