[英]How to get min height/width of parent element and set to it's child height/width by CSS
[英]How to get width and height of an element on the page?
借助可爱的jQuery?
jQuery有两种方法,即width和height,可以做到这一点:
$(".myElement").width();
$(".myElement").height();
您还可以使用它们来设置值:
$(".myElement").width(200); // set element to 200px
可以在文档中找到更多信息: http : //api.jquery.com/width/和http://api.jquery.com/height/
$.innerHeight()
- 获取匹配元素集合中第一个元素的当前计算高度,包括填充,但不包括边框。 $.innerWidth()
- 获取匹配元素集中第一个元素的当前计算宽度,包括填充,但不包括边框。 $.outerHeight()
- 获取匹配元素集中第一个元素的当前计算高度,包括填充和边框。 $.outerWidth()
- 获取匹配元素集合中第一个元素的当前计算宽度,包括填充和边框。 使用height(...)
和width(...)
方法:
alert($(body).height());
alert($(body).width());
你永远不会猜到...
var width = $(selector).width();
var height = $(selector).height();
在各种有用的情况下, Mac Firefox / Mozilla上的width值通常是错误的 。
-错误的意思是,如果您将封闭的div设置为所报告的子文本的“宽度”,则会得到换行。
问题在于,在Mac Firefox / Mozilla上,Firefox使用亚像素字体渲染。 返回的宽度是地板,而不是真正宽度的天花板,即浮动。
我的错误报告提供了针对Firefox的解决方法,或者总是将宽度添加1px,这样您就可以了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.