CSS3 selector: CSS Selector

Source: Internet
Author: User
Tags xmlns

When I was looking at jquery, I could not understand why $ () The factory method can do so many things, the choice of DOM is too powerful! Today read the "Introduction of CSS" This book, the original CSS itself there are so many selectors, before looking at jquery code, has not figured out how jquery analysis of the parameters inside. Summed up an experience: The foundation is not good do not look at those frames, the more you look more confused.
Anyway
1, class selector
. planet{
Position:absolute;
top:0;
left:0;
bottom:15px;
}
Start with a point, followed by the class name itself, class name cannot have spaces
In the paging file, suppose there is such a paragraph:
This is a class demo

The attributes in the style sheet are applied to this div
You can also write this in the style sheet:
Div. planet{
Position:absolute;
top:0;
left:0;
bottom:15px;
}
Applying more than one class to a label can be written like this:

The middle is separated by a space.
2,id Selector
#planet {
Position:absolute;
top:0;
left:0;
bottom:15px;
The}id selector starts with a #, the name of the ID, and the ID should be defined once in each document, so the ID selector is unique.
Demo:



class and ID selectors




PMS is produced by the transformation from "production" to "consumer" as the center of Industrial production, and for enterprises,
The fundamental aim is to produce "marketable" products with limited resources and to maintain long-term profitability and development.



PMS is produced by the transformation from "production" to "consumer" as the center of Industrial production, and for enterprises,
The fundamental aim is to produce "marketable" products with limited resources and to maintain long-term profitability and development.



PMS is produced by the transformation from "production" to "consumer" as the center of Industrial production, and for enterprises,
The fundamental aim is to produce "marketable" products with limited resources and to maintain long-term profitability and development.



PMS is produced by the transformation from "production" to "consumer" as the center of Industrial production, and for enterprises,
The fundamental aim is to produce "marketable" products with limited resources and to maintain long-term profitability and development.



</HTML>CSS:
body{
font-family:sans-self;
}
p.container{
border:1px solid RGB (29,179,82);
Background:rgb (202,222,245);
padding:10px;
width:245px;
height:245px;
Float:left;
margin:10px;
}
p.box{
border:1px solid RGB (69,199,115);
Background:rgb (164,201,245);
}
p.tank{
border:1px solid RGB (107,214,145);
Background:rgb (124,180,245);
Clear:left;
}
p#container-1234{
border:1px solid RGB (154,232,181);
Background:rgb (82,157,245);
}
Results:

3, Universal Selector
Very simple: *, this is the universal selector
*{
BORDER:1PX solid black;
}
4, descendant selector
The descendant selector determines whether a style is applied based on whether an element is a descendant of another element.
In CSS, "descendant" means that one element is another's son, grandson, grandchild, and so on, the plain thing is in the code: The inner element is the descendant of the outer element.
In the stylesheet, the spaces between the selectors indicate the relationship between the ancestors and the descendants, the ancestors in the front, and the descendants in the rear.

Above: There is a div with the body ID in the document, and the span applied style for a class named Inline-code in this div:
Font-family:monospace
The above selector can be applied






can also be applied to:








5, Direct Sub Selector
A direct child selector is very similar to a descendant selector, except that the direct child selector applies only to the immediate child element of the element

Separated by a ">"
You can also add as many elements as you want to the direct child selector chain

can also be mixed with descendant selectors

6, adjacent selector
The adjacent selector selects the next element of an element, separated by a "+" in the middle
H1 + p{
Background:lightyellow;
Color:darkkhaki;
border:1px solid Darkkhaki;
}
H1 + P + p{
Background:yellowgreen;
Color:green;
border:1px solid Green;
The first choice is the

element that follows the

element directly
The second option is that a

element is directly adjacent to another

element, and the latter is directly adjacent to a

element.
A complete example:
body{
FONT:12PX Sans-serif;
}
p{
padding:5px;
}
H1 + p{
Background:lightyellow;
Color:darkkhaki;
border:1px solid Darkkhaki;
}
H1 + P + p{
Background:yellowgreen;
Color:green;
border:1px solid Green;
}



adjacent selector




Next Sibling Selectors


ajax is used to describe technologies that have been in existence for a long time: JavaScript code, XML, and objects that can be called asynchronously via HTTP. Ajax is often used to avoid submitting and reloading the entire Web page, especially if the user does not need to reload the entire page.
In the past few years, AJAX-enabled sites are constantly improving, and as a development tool for such sites, Ajax applications are becoming more widespread. Use the practice of this article to build better Web applications with Ajax and JavaScript this article links http://www.cxybl.com/html/wyzz/CSS/20121128/34564.html

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.