小白教程
所有教程
关于
Search
172.69.59.163
172.69.59.163
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Css offsetparent”的源代码
本页内容
上一节:
Css_offset
下一节:
Html_outerheight
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:offsetParent()}}[[Category:jquery ref html|19]] = jQuery offsetParent() 方法 = [[jquery ref html|jQuery HTML/CSS 方法]] 设置 <p> 元素的最近定位的祖先元素的背景颜色: <sample title="" desc="" lang="html" hererun="1"> $("button").click(function(){ $("p").offsetParent().css("background-color","red"); }); </sample> <run name=""> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>小白教程(xiaobai.wang)</title> <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"> </script> <script> $(document).ready(function(){ $("button").click(function(){ $("p").offsetParent().css("background-color","red"); }); }); </script> </head> <body> <button>设置背景颜色</button> <div style="border:1px solid black;width:70%;position:absolute;left:10px;top:50px"> <div style="border:1px solid black;margin:50px;background-color:yellow"> <p>点击按钮这一段的设置第一个定位的父元素的背景颜色。</p> </div></div> </body> </html> </run> == 定义和用法 == offsetParent() 方法返回第一个定位的祖先元素。 '''提示:'''通过 jQuery 或 CSS 的 position 属性(relative、absolute 或 fixed)对元素进行定位。 == 语法 == <pre> $(selector).offsetParent()</pre> [[jquery ref html|jQuery HTML/CSS 方法]]
返回至“
Css offsetparent
”。
上一节:
Css_offset
下一节:
Html_outerheight