jQuery API/1.1.1/CSS
2007-01-23 21:48 无常 阅读(998) 评论(0) 编辑 收藏 举报css( name )
访问第一个匹配元素的style属性。此方法使得第一个匹配元素的style属性更加容易。
Return value: String
Parameters:
name (String)
: 要访问的CSS属性名。
Example:
检索第一段的颜色样式。
$("p").css("color");
Before:
<p style="color:red;">Test Paragraph.</p>
Result:
"red"
Example:
检索第一段的font-weight样式。
$("p").css("font-weight");
Before:
<p style="font-weight: bold;">Test Paragraph.</p>
Result:
"bold"
css( properties )
将key/value 样式属性设置到所有匹配元素。
这是个给所有匹配元素设置大量CSS的好方法。
Return value: jQuery
Parameters:
properties (Map)
: Key/value pairs to set as style properties.
Example:
设置所有段落元素设置color和background样式。
$("p").css({ color: "red", background: "blue" });
Before:
<p>Test Paragraph.</p>
Result:
<p style="color:red; background:blue;">Test Paragraph.</p>
css( key, value )
给所有匹配的元素设置单个样式。如果vale是一个数字,将自动转换为piexl格式。
Return value: jQuery
Parameters:
key (String)
: 属性名value (String|Number)
: 属性值。
Example:
将所有段落的color样式设置为红色。
$("p").css("color","red");
Before:
<p>Test Paragraph.</p>
Result:
<p style="color:red;">Test Paragraph.</p>
Example:
将所有段落的left样式改为30px。
$("p").css("left",30);
Before:
<p>Test Paragraph.</p>
Result:
<p style="left:30px;">Test Paragraph.</p>
height()
取得第一个匹配元素的像素高。
Return value: String
Example:
$("p").height();
Before:
<p>This is just a test.</p>
Result:
300
height( val )
给所有匹配的元素设置CSS宽度。如果没指定单位(如'em'或'%')则自动加了'px'单位。
Return value: jQuery
Parameters:
val (String|Number)
:设置CSS属性为指定值。
Example:
$("p").height(20);
Before:
<p>This is just a test.</p>
Result:
<p style="height:20px;">This is just a test.</p>
Example:
$("p").height("20em");
Before:
<p>This is just a test.</p>
Result:
<p style="height:20em;">This is just a test.</p>
width()
取得第一个匹配元素的像素宽度。
Return value: String
Example:
$("p").width();
Before:
<p>This is just a test.</p>
Result:
300
width( val )
设置每个匹配元素的CSS宽度。如果没指定单位(如'em'或'%')则自动加了'px'单位。
Return value: jQuery
Parameters:
val (String|Number)
: 设置CSS属性为指定值。
Example:
$("p").width(20);
Before:
<p>This is just a test.</p>
Result:
<p style="width:20px;">This is just a test.</p>
Example:
$("p").width("20em");
Before:
<p>This is just a test.</p>
Result:
<p style="width:20em;">This is just a test.</p>
无常翻译:http://wuchang.cnblogs.com
wuChang@guet.edu.cn
QQ: 3263262
Retrieved from "http://www.docs.jquery.com/API/1.1.1/CSS"
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架