Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Appendix H. CSS

Appendix H. CSS

MethodDescriptionReturn Value
CSS
css(property)Returns the specified CSS property value from the first selected element, for example:
$('div').css('background-color')

String
css(properties)Sets the specified CSS properties. The properties argument is defined as an object literal of key, value pairs, for example:
$('div').css({
  backgroundColor: 'red',
  marginLeft: '10px'
});

jQuery
css(property, value)Sets the specified CSS property value, for example:
$('div').css('background', 'red');

jQuery
Positioning
offset()Returns the offset position of the first selected element relative to the viewport.
var $offset = $('div').offset();
alert('Left: ' + $offset.left);
alert('Top: ' + $offset.top);

Object
Height and Width
height()Returns the pixel height (CSS height, excluding borders and padding) of the first selected element.Integer
height(value)Sets the pixel height (CSS height) of the first selected element. If no unit of measurement is provided, px (pixels) is used.jQuery
width()Returns the pixel width (CSS width, excluding borders and padding) of the first selected element.Integer
width(value)Sets the pixel width (CSS width) of the first selected element. If no unit of measurement is provided, px (pixels) is used.jQuery
outerHeight(options)Returns the offsetHeight (includes the pixel height, borders, and padding) of the first selected element. The options argument is a JavaScript object literal of options. See the "Options" section for more information.Integer
outerWidth(options)Returns the offsetWidth (includes the pixel width, borders, and padding) of the first selected element. The options argument is a JavaScript object literal of options. See the "Options" section for more information.Integer


Options


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial