Element.clientTop - Web APIs 编辑
The width of the top border of an element in pixels. It is a read-only, integer property of element.
As it happens, all that lies between the two locations (offsetTop
and client area top) is the element's border. This is because the offsetTop
indicates the location of the top of the border (not the margin) while the client area starts immediately below the border, (client area includes padding.) Therefore, the clientTop value will always equal the integer portion of the .getComputedStyle()
value for "border-top-width". (Actually might be Math.round(parseFloat()).) For example, if the computed "border-top-width" is zero, then clientTop
is also zero.
Note: This property will round the value to an integer. If you need a fractional value, use element.getBoundingClientRect()
.
Gecko-based applications support clientTop
starting with Gecko 1.9 (Firefox 3, implemented in bug 111207). This property is not supported in Firefox 2 and earlier.
Syntax
var top = element.clientTop;
Example
In the following illustration, the client area is show in white. (The segments labeled "Top", "Right", etc. have no significance regarding the client area.) The clientTop value is the distance from where the margin (yellow) area ends and the padding and content areas (white) begin.
padding-top
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
padding-bottom
Left Top Right Bottom margin-top margin-bottom border-top border-bottomNotes
clientTop
was first introduced in the MS IE DHTML object model.
Specifications
Specification | Status | Comment |
---|---|---|
CSS Object Model (CSSOM) View Module The definition of 'clientTop' in that specification. | Working Draft |
Browser compatibility
BCD tables only load in the browser
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论