CSS - Selectors Flashcards
:link
The:linkselector is used to select unvisited links.
Note:The :link selector does not style links you have already visited.
:visited
The:visitedselector is used to select visited links.
a:visited{
color:pink;
}
:hover
Select and style a link when you mouse over it:
a:hover{
background-color:yellow;
}
:active
Select and style the active link:
a:active{
background-color:yellow;
}
element>element
Select and style every <p> element where the parent is a </p><div> element:
div > p{
background-color:yellow;
}
</div>
element+element
Select and style the first <p> element that are placed immediately after </p><div> elements:
div + p{
background-color:yellow;
}
</div>
element1~element2
Set a background color for all <ul> elements that are preceded by a <p> element with the same parent:
p ~ ul{
background:#ff0000;
}
</p></ul>
[attribute]
Style all <a> elements with a target attribute:</a>
a[target]{
background-color:yellow;
}
</a>
[attribute=value]
Style <a> elements with a target=”_blank”:</a>
a[target=_blank]{
background-color:yellow;
}
</a>
[attribute~=value]
Select and style elements with a title attribute containing the word “flower”:
[title~=flower]{
background-color:yellow;
}
[attribute|=value]
Select and style elements, where the lang attribute’s value starts with “en”:
[lang|=en]{
background-color:yellow;
}
[attribute^=value]
Set a background color on all <div> elements that have a class attribute value that begins with “test”:
div[class^=”test”]{
background:#ffff00;
}
</div>
[attribute$=value]
Set a background color on all <div> elements that have a class attribute value that ends with “test”:
div[class$=”test”]{
background:#ffff00;
}
</div>
[attribute*=value]
Set a background color on all <div> elements that have a class attribute value containing “test”:
div[class*=”test”]{
background:#ffff00;
}
</div>
::after
Insert some text after the content of each <p> element:
p::after{
content:” - Remember this”;
}
</p>
::before
Insert some text before the content of each <p> element:
p::before{
content:”Read this: “;
}
</p>
:checked
Set the height and width for all checked elements:
input:checked{
height:50px;
width:50px;
}
:default
Add a red shadow color to the default input element:
input:default{
box-shadow:0 0 1px 1px red;
}
:disabled
Set a background color for all disabled input elements of type=”text”:
input[type=”text”]:disabled{
background:#dddddd;
}
:empty
Specify a background color for empty <p> elements:
p:empty{
background:#ff0000;
}
</p>
:enabled
Set a background color for all enabled elements of type=”text”:
input[type=”text”]:enabled{
background:#ffff00;
}
:first-child
Select and style every <p> element that is the first child of its parent:
p:first-child{
background-color:yellow;
}
</p>
::first-letter
Select and style the first letter of every <p> element:
p::first-letter{
font-size:200%;
color:#8A2BE2;
}
</p>
::first-line
Select and style the first line of every <p> element:
p::first-line{
background-color:yellow;
}
</p>
element of its parent: p:first-of-type { background: red; }
element with a lang attribute value equal to "it" (Italian): p:lang(it) { background: yellow; }
element that is the last child of its parent: p:last-child { background: #ff0000; }
element of its parent: p:last-of-type { background: #ff0000; }
element: :not(p) { background: #ff0000; }
element that is the second child of its parent, counting from the last child: p:nth-last-child(2) { background: red; }
element that is the second p element of its parent, counting from the last child: p:nth-last-of-type(2) { background: red; }
element that is the only child of its type, of its parent: p:only-of-type { background: #ff0000; }
element that is the only child of its parent: p:only-child { background: #ff0000; }
element that is inside
elements AND all
elements: h2, p { background-color: yellow; }
element with the class "intro": p.intro { background-color: yellow; }
elements: p { background-color: yellow; }