pseudo css selectors

25
Pseudo CSS Selectors

Upload: -

Post on 05-Jul-2015

3.182 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Pseudo CSS Selectors

Pseudo CSS Selectors

Page 2: Pseudo CSS Selectors

Link-related pseudo class selectors

Page 3: Pseudo CSS Selectors

:link

<a href = “google.com”>unvisited link</a>

/* set default style for unvisited link */

a:link{

color : blue; text-decoration : underline;

}

Page 4: Pseudo CSS Selectors

:visited

<a href = “google.com”>visited link</a>

/* set default style for visited link */

a: visited{

color : red;

text-decoration : underline;

}

Page 5: Pseudo CSS Selectors

:active

<a href = “google.com”>visited link</a>

/* set selected state style for a link */

a: active{

color : red;

}

Page 6: Pseudo CSS Selectors

:hover

<a href = “google.com”>visited link</a>

/* set mouseover style for link */

a: hover{

color : red;

}

Page 7: Pseudo CSS Selectors

Input & link related pseudo class selectors

Page 8: Pseudo CSS Selectors

:focus

<input type = “text” name=“user_name”/>

/* onfocus change field background */

input: focus{

background : red;

}

Page 9: Pseudo CSS Selectors

:target

<a href = “#set”>SET</a>

<div id =“set”>This is set</div>

/* change style of target element */

: target {

background : red;

}

Page 10: Pseudo CSS Selectors

:enabled | :disabled

<input type = “text” />

<input type = “text” disabled="disabled"/>

Input : enabled { /* change style of enabled element */

background : red;

}

Input : disabled { /* change style of enabled element */

background : blue;

}

Page 11: Pseudo CSS Selectors

:checked

<input type = “checkbox” checked="checked"/>

<input type = “radio” checked="checked" />

<input type = “checkbox” checked="checked"/>

/* change style of checked element */

Input : checked{

width : 200px;

}

Page 12: Pseudo CSS Selectors

Position/Number-based pseudo class selectors

Page 13: Pseudo CSS Selectors

:root

/* SELECT ROOT Document Element */

:root{

background : red;

}

/* Will select the <html> element*/

Page 14: Pseudo CSS Selectors

:first-child | :last-child

<ul> <li>A</li> <li>B</li> <li>C</li> </ul>

ul li : first-child { /* select first item*/

background : blue;

}

ul li : last-child { /* select last item*/

background : red;

}

Page 15: Pseudo CSS Selectors

:nth-child(N) | :nth-last-child(N)

<ul> <li>A</li> <li>B</li> <li>C</li> </ul>

ul li : nth-child(N/odd|even) {

background : blue;

}

ul li:nth-last-child(N/odd|even){

background : red;

}

Page 16: Pseudo CSS Selectors

:first-of-type | :last-of-type

<div> <p>A</p> <span>B</span> <p>C</p> </div>

div p : first-of-type { /* select first item of type p */

background : blue;

}

div p : last-of-type { /* select last item of type p*/

background : red;

}

Page 17: Pseudo CSS Selectors

:nth-of-type(N) | :nth-last-of-type(N)

<div> <p>A</p> <span>B</span> <p>C</p> </div>

div p : nth-of-type(N/odd|event){

background : blue;

}

div p : nth-of-type(N/odd|event){

background : red;

}

Page 18: Pseudo CSS Selectors

:only-of-type

<div> <p>A</p> <span>B</span> <p>C</p> </div>

/* select only one element from type span */

div span : only-of-type {

background : blue;

}

Page 19: Pseudo CSS Selectors

Relational pseudo class selectors

Page 20: Pseudo CSS Selectors

:not(S)

<div class=“element”></div>

<span class=“element”></span>

<p class=“element”></p>

/* select all non span elements */

.element : not(span) {

background : blue;

}

Page 21: Pseudo CSS Selectors

:empty

<p></p> <!-- select first item -->

<p>Content</p>

/* select the empty p element */

p : empty {

background : blue;

}

Page 22: Pseudo CSS Selectors

Text-related pseudo class selectors / elements

Page 23: Pseudo CSS Selectors

:first-letter | :first-line

<p> Lorem ipsum dolor si amet </p>

p : first-letter { /* change first letter of text style*/

font-size : 25px;

font-weight : bold

}

p : firs-line { /* change first line of text style*/

text-decoration : underline

}

Page 24: Pseudo CSS Selectors

Content-related pseudo "elements"

Page 25: Pseudo CSS Selectors

:before | :after

<span> Some text </span>

span : before { /* add extra content before span */

content : “ … ”

}

span : after { /* add extra content before span */

content : “ … ”

}