Jquery (4): CSS APIs

Source: Internet
Author: User

CSS

This article is simple. You can find APIs such as background and color when you view previous documents, but you cannot find them in Versions later than 1.2. Still use CSS () directly ....

CSS
CSS (name ):
Access the style attribute of the First Matching Element

Example: $ ("p" ).css ("color ");

 

CSS (properties ):Set"Name/value pair"The object is set to the style attribute of all matching elements.

Example: $ ("P" ).css ({color: "# ff0011", Background: "blue "});

If the property name contains"-"Words,Quotation marks are required: $ ("P" ).css ({"margin-left": "10px", "background-color": "blue "});

 

CSS (name, value):Among all matched elements,Set the value of a style attribute,The number is automatically converted to the pixel value.

Example: $ ("P" ).css ("color", "Red ");

 

Location
Offset ():
Obtains the relative offset of the matching element in the current view. The returned object contains two integer attributes: Top and left. This method is only valid for visible elements.

<P> Hello </P> <p> 2nd paragraph </P>

Code:

VaR P = $ ("P: Last ");

VaR offset = P. offset ();

P.html ("Left:" + offset. Left + ", top:" + offset. Top );

Result: <P> Hello </P> <p> left: 0, top: 35 </P>

 

Width and height
Height ()
:Obtains the height calculated for the First Matching Element.(PX). Can be used to obtainWindowAndDocumentHigh

Code: $ ("P"). Height ();

Code: $ (Document). Height ();//Retrieve document height

 

Height (VAL):Set for each Matching ElementCSSHeight(Hidth)Attribute Value. If the unit (such as em or %) is not explicitly specified, PX is used.

Code: $ ("p"). Height (20 );

 

Width ():Obtains the current calculated width (PX) of the First Matching Element ). Can be used to obtain the height of the window and document

Width (VAL ):Set the CSS width attribute value for each matching element.

 

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.