Juqery Learning six css--css, position, width and height _jquery

Source: Internet
Author: User
CSS (name)
Accesses the style properties of the first matching element.

--------------------------------------------------------------------------------

Return a style property on the the matched element.
return value
String

Parameters
Name (String): Property names to access

Example
Gets the value of the color style property of the first paragraph.

JQuery Code:

$ ("P"). CSS ("color");
--------------------------------------------------------------------------------------------------------------- ----------------------------------
CSS (properties)
Sets a "name/value pair" object to the style properties of all matching elements.
This is the best way to set a large number of style attributes on all matching elements.

--------------------------------------------------------------------------------

Set a Key/value object as style properties to all matched elements.
This is the best way to set several style properties on all matched elements.
return value
Jquery

Parameters
Properties (MAP): name/value pairs to be set to style properties

Example
Sets the font color for all paragraphs to red and the background to blue.

JQuery Code:

$ ("P"). CSS ({color: "#ff0011", Background: "Blue"});

--------------------------------------------------------------------------------

If the property name contains "-", you must use quotation marks:

JQuery Code:

$ ("P"). css ({"Margin-left": "10px", "Background-color": "Blue"});
--------------------------------------------------------------------------------------------------------------- ----------------------------------
CSS (Name,value)
In all matching elements, set the value of a style property.
Numbers are automatically converted to pixel values

--------------------------------------------------------------------------------

Set a single style property to a value of all matched elements.
If A is provided, it's automatically converted into a pixel value.
return value
Jquery

Parameters
Name (value): Property name

Value (String, Number): property value

Example
Set all paragraph fonts to red

JQuery Code:

$ ("P"). CSS ("Color", "red");
--------------------------------------------------------------------------------------------------------------- ----------------------------------
Offset ()
Gets the relative offset of the matching element at the current viewport.
The returned object contains two cosmetic properties: Top and left. This method is valid only for visible elements.

--------------------------------------------------------------------------------

Get the current offset of the the ' the ' matched element relative to the viewport.
The returned object contains two Integer properties, top and left. The method works only with visible elements.
return value
Object{top,left}

Example
Gets the offset of the second paragraph

HTML Code:

<p>hello</p><p>2nd paragraph</p>
JQuery Code:

var p = $ ("P:last");
var offset = P.offset ();
P.html ("Left:" + Offset.left + ", Top:" + offset.top);
Results:

<p>hello</p><p>left:0, top:35</p>
--------------------------------------------------------------------------------------------------------------- ----------------------------------
Height ()
Gets the height value (px) of the current calculation of the first matching element.
Can be used after jQuery 1.2 to get the window and document high

--------------------------------------------------------------------------------

Get the current computed, pixel, the height of the the the the-matched element.
In JQuery 1.2, this is able to find the height of the window and document.
return value
Integer

Example
Get the height of the first paragraph

JQuery Code:

$ ("P"). Height ();

--------------------------------------------------------------------------------

Get the height of the document

JQuery Code:

$ (document). Height ();
Set the height of all paragraphs to 20:

JQuery Code:

$ ("P"). Height (20);
--------------------------------------------------------------------------------------------------------------- ----------------------------------
Width ()
Gets the width value (px) currently computed for the first matching element.
Can be used after jQuery 1.2 to get the width of Windows and document

--------------------------------------------------------------------------------

Get the current computed, pixel, width of the the ' the ' the ' the ' the ' the ' the '
In JQuery 1.2, this is able to find the width of the window and document.
return value
Integer

Example
Get the width of the first paragraph

JQuery Code:

$ ("P"). width ();

--------------------------------------------------------------------------------

Gets the width of the current window

JQuery Code:

$ (window). width ();
Set the width of all paragraphs to 20:

JQuery Code:

$ ("P"). Width (20);
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.