wide range selectors
h1, h2, h3, h4 { text-align: center; }
.highlight p, .highlight ul { margin-left: 10px; }
#main p { padding-top: 10px; }
.highlight p, .highlight ul { margin-left: 10px; }
#main p { padding-top: 10px; }
type selectors(element selectors)
h1 { text-align: center; }
class selectors
/*simple class selector*/
.big { text-align: center; }
<p class="big">This is some text</p>
/*combining class and type selectors*/
p.big { color: blue; }
div.big { color: red; }
/*combining multiple classes*/
.big { font-weight: bold; }
.indent { padding-left: 2px; }
<p class="big indent">
.big { text-align: center; }
<p class="big">This is some text</p>
/*combining class and type selectors*/
p.big { color: blue; }
div.big { color: red; }
/*combining multiple classes*/
.big { font-weight: bold; }
.indent { padding-left: 2px; }
<p class="big indent">
ID selectors
#navigation { width: 50%; color: #333; }
div#navigation { width: 50%; color: #333; }
div#navigation { width: 50%; color: #333; }
descendant selectors
p span { color: red; }
<p>This is a <span>test</span></p>
<p>This is a <span>test</span></p>
child selectors
p > span { color: red; }
<p>This is a <span>test</span></p>
<span>outside p element test</span>
<p>This is a <span>test</span></p>
<span>outside p element test</span>
NOTE: not supported by Windows Internet Explorer 5, 5.5 and 6
Adjacent sibling selectors
p + span { color: red; }
<p>This is a <span>test</span></p>
<span>outside p element test</span>
NOTE: not supported by Windows Internet Explorer 5, 5.5 and 6<p>This is a <span>test</span></p>
<span>outside p element test</span>
Attribute selectors
input[type=text] { width: 50%; }
<input type="text" value="text" />
<input type="button" value="button" />
NOTE: not supported by Windows Internet Explorer 5, 5.5 and 6<input type="text" value="text" />
<input type="button" value="button" />
Pseudo-classes
/*element hierarchy*/
:first-child
/*hyper link styling*/
:link
:visited
/*mouse over*/
:hover
/*mouse down*/
:active
/*other*/
:focus
:lang(n)
NOTE: not supported by Windows Internet Explorer 5, 5.5 and 6:first-child
/*hyper link styling*/
:link
:visited
/*mouse over*/
:hover
/*mouse down*/
:active
/*other*/
:focus
:lang(n)
Pseudo-elements
/*the first letter or the first line of text appears*/
:first-line
:first-letter
/*before or after an element on the page*/
:before
:after
NOTE: not supported by Windows Internet Explorer 5, 5.5 and 6:first-line
:first-letter
/*before or after an element on the page*/
:before
:after
Reference:
Selectutorial - CSS selectors
沒有留言:
張貼留言