jQuery CSS 函數
jQuery CSS 操作
jQuery 擁有三種用于 CSS 操作的重要函數:
- $(selector).css(name,value)
- $(selector).css({properties})
- $(selector).css(name)
CSS 操作實例
函數 css(name,value) 為所有匹配元素的給定 CSS 屬性設置值:
實例
$(selector).css(name,value) $("p").css("background-color","red");
函數 css({properties}) 同時為所有匹配元素的一系列 CSS 屬性設置值:
實例
$(selector).css({properties}) $("p").css({"background-color":"red","font-size":"200%"});
函數 css(name) 返回指定的 CSS 屬性的值:
實例
$(selector).css(name) $(this).css("background-color");
jQuery Size 操作
jQuery 擁有兩種用于尺寸操作的重要函數:
- $(selector).height(value)
- $(selector).width(value)
Size 操作實例
函數 height(value) 設置所有匹配元素的高度:
實例
$(selector).height(value) $("#id100").height("200px");
函數 width(value) 設置所有匹配元素的寬度:
實例
$(selector).width(value) $("#id200").width("300px");
jQuery CSS 函數 - 來自本頁
CSS 屬性 | 描述 |
---|---|
$(selector).css(name,value) | 為匹配元素設置樣式屬性的值 |
$(selector).css({properties}) | 為匹配元素設置多個樣式屬性 |
$(selector).css(name) | 獲得第一個匹配元素的樣式屬性值 |
$(selector).height(value) | 設置匹配元素的高度 |
$(selector).width(value) | 設置匹配元素的寬度 |
如需完整的參考手冊,請訪問我們的 jQuery CSS 函數參考手冊。