Through plenty of CSS web designers experience, we can remember all kind of code syntax, compatibility and fragments. Certain CSS, you can really help change your web design change older technology rules and statements, use less code to write the same effect is we have been constantly pursuing the goal of the
here are five CSS selectors will help you keep your XHTML page cleaner
1, the subclass matching
code is as follows:


<! PUBLIC DOCTYPE HTML "-///DTD/W3C XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
<HTML XMLNS="http://www.w3.org/1999/xhtml" XML: lang="en" >
<Head>
<STYLE>
/* styles here */
</style>
</head>
<Body>
<Ul class="list" >
<Li class="item" >Item 1 </li>
<Li class="item" active >The active item 2 </li>
<Li class="active" >Item 3 </li>
</ul>
</body>
</html>

the typical solution is to use the parent element, for example:
list. Item {color: # CCC; }/* all of the elements' item 'class */
in the list. The active {text - decoration: underline; * * all elements &}/other Item” And &other Active” Class * *
however, if you need to rule out &other; Active” Class element, but leave &other; Item“ , what should you do? Here is the subset matching the selector code:

  code is as follows:  


<! PUBLIC DOCTYPE HTML "-///DTD/W3C XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
<HTML XMLNS="http://www.w3.org/1999/xhtml" XML: lang="en" >
<Head>
<STYLE>
item {color: # CCC; }/* all elements with the class 'item' */
in the item. The active {text - decoration: underline; }/* all element with 'item' and 'active' class */
</style>
</head>
<Body>
<Ul>
<Li class="item" >. The item CSS selector applied

<Li class="item" active >, the item and the item. The active CSS selectors applied </li>
<Li class="item" active someOneMoreClass >, the item and the item. The active CSS selectors applied too

<Li class="active" >No CSS selectors applied

</ul>
</body>
</html>

the browser support: firefox, Chrome, Safari, Internet explorer 7 and above
2, attributes, select
code is as follows:


<! PUBLIC DOCTYPE HTML "-///DTD/W3C XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
<HTML XMLNS="http://www.w3.org/1999/xhtml" XML: lang="en" >
<Head>
<STYLE>
label {display: block; Color: # 444; }
input. The text {border: 1 px solid # CCC; Color: # 333; Padding: 3 px; }//define the another class for a text box
input. Submit {color: # 333; Border: 1 px solid # 333; Background - color: # eee; }//to the submit button to define a class
</style>
</head>
<Body>
<Form>
<The label for="login" >Login
<The input class="text" type="text" name="login" id="login" value=""/>
<The label for="login" >Password
<Input class="text" type="password" name="password", "id=" password ", "value=" "/>

<Input class="submit" type="submit" value="http://www.script-home.com//web/Push me"/>
</form>
</body>
</html>

it is right, but I have a solution, no additional definition class, for that matter, I will use the attribute selectors:

  code is as follows:  


/* matches any element &other; NAME” Set of properties (any) */
a [name] {... Styles.. }
/* matches any INPUT element for &other; Type” For the attribute value &other; Text/*
input (type="text") {... Styles.. }
/* matches any DIV element, its &other; Myattribute” Attribute value is a space separated list of values, one of which is a completely equal &other; Value3 &throughout; .
anyone with <Div myattribute="value1 value2 value3" value4 >*
div [myattribute ~="value3"] {... Styles.. }
/* matches any DIV element, its &other; Myattribute” Attribute has a value separated by a hyphen.
anyone with <Div myattribute="value1, value2, value3 - value4" >*
div [myattribute ~="value2"] {... Styles.. }

so using these rules can write such code style

  code is as follows:  


<STYLE>
label {display: block; Color: # 444; }
/* all text - and password - inputs */
input (type="text"), input (type="password"] {border: 1 px solid # CCC; Color: # 333; Padding: 3 px; }
/* */
buttons just submit input [type="submit"] {color: # 333; Border: 1 px solid # 333; Background - color: # eee; }
</style>
<Form>
<The label for="login" >Login
<Input type="text" name="login" id="login" value=""/>
<The label for="password" >Password
<Input type="password" name="password", "id=" password ", "value=" "/>

<Input type="submit" value="http://www.script-home.com//web/Push me"/>
</form>

the browser support: firefox, Chrome, Safari, Internet explorer 7 and above.
3, adjacent selector
code is as follows:


/* match in a &other elements at the same level Active” Before any one element/
* * a.a ctive + a
/* match in a &other elements at the same level Active” Any element of a * * after class/
a + a.a ctive
/*... And some useful tips... *
/* all the li element matched except the last */
li + li {.. Style.. }
/* matches A: hover the first element of the */
A: hover {/* first style: hover */}
/* in addition to the first hovering elements of style */

A + A: hover {.. Styles.. }

it can be used, for example the &# 8203; The &# 8203; The style of the menu, etc.
here is the use of adjacent selector easier way:

  code is as follows:  


<! PUBLIC DOCTYPE HTML "-///DTD/W3C XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
<HTML XMLNS="http://www.w3.org/1999/xhtml" XML: lang="en" >
<Head>
<STYLE>
the menu a {
/* */
the style of the menu item border: 1 px solid # 888;
the padding: 3 px 10 px;
color: # 333;
background - color: # FFF;
text - decoration: none;
margin: 0;
float: left;
z - index: 1;
position: relative;

}. The menu a: hover {
z - index: 10000;
position: relative;
the padding: 8 px 20 px 8 px 20 px;
background - color: # aed8fb;
border - left: 1 px solid # 888;
margin: 0-5 p - 10 px - 10 px;

}. The menu a + a: hover {
margin - right: - 10 px;
margin - left: - 11 px;

}. The menu a + a {
border - left: none;

}. The menu. The clear {
float: none;
clear: both;
}
</style>
</head>
<Body>
<Div class="menu" >
<A href="http://www.script-home.com//web/#" >Item 1 </a>
<A href="http://www.script-home.com//web/#" >Item 2 </a>
<A href="http://www.script-home.com//web/#" >Item 3 </a>
<A href="http://www.script-home.com//web/#" >Item 4 </a>
<Div class="clear" ></div>
</div>
</body>
</html>

the browser support: firefox, Chrome, Safari, Internet explorer 7 and above
4. Child selectors,
code is as follows:


<Div class="content" >
<P> Lorem Lorem Lorem <Img SRC="http://www.script-home.com/images.jpg" Alt="this image should be aligned left"/></p>
<P> Lorem Lorem Lorem <Img SRC="http://www.script-home.com/images.jpg" Alt="this image should be aligned left too"/>Lorem Lorem Lorem </p>
<Img SRC="http://www.script-home.com/images.jpg" Alt="this image shouldn 't be aligned left too/>" "
</div>

you can do the following:
div. The content of p >Img {float: left; }
the browser support: firefox, Chrome, Safari, Internet explorer 7 and above.
5, general selection skills
code is as follows:


/* all matched elements &other; Href” [href attributes */
*] {.. Styles.. }
/* all of the matched elements' Alt 'empty properties */*

[Alt=""]/* Matches all P elements which are grandchild (not direct child) of the DIV element */
* P {DIV.. Styles.. }

the browser support: firefox, Chrome, Safari, Internet explorer 7 and above.


This concludes the body part