Estelle Weyl
www.standardista.com
@estellevw
@standardista




Estelle Weyl | @estellevw | Github | Press → key to advance.




<ul> <li id="myID" class="myClass">item 1</li> <li class="myClass">item 2</li> <li>item 3</li> </ul>
var chil = $('#bar .foo');
Natively
var el = document.querySelector('#bar');
var chil = el.querySelectorAll('.foo');
or
chil = document.querySelectorAll('#bar .foo');
All supported since IE9, and all other browsers
E[att] {/* has the attribute at all */}
E[att=val] {/* exact */}
E[att~=val] {/* val is a space separated word */}
E[att|=val] {/* with a dash */}
E[att^=val] {/* begins with val */}
E[att$=val] {/* ends with val */}
E[att*=val] {/* val is anywhere as a substring */}
@media print{
abbr[title]:after {
content: "(" attr(title) ")";
}
a[href^=http]:after {
content: "(" attr(href) ")";
}
}
Note: Multiple attributes work! a[title][href]
Note: The top line of the example is editable. The CSS will impact the contents on the rest of the page.
:nth-child() :nth-last-child() :nth-of-type() :nth-last-of-type() :first-child* :last-child :first-of-type :last-of-type :only-child :only-of-type :root :empty :not(:empty)
:first-child :last-child :first-of-type :last-of-type :only-child :only-of-type
Easier to explain by example
:nth-child(3n) :nth-last-child(odd) :nth-of-type(5) :nth-last-of-type(3n+1)
Target element or elements based on argument passed to the selector
li:first-child,
li:last-child {
font-weight: bold;
}
li:first-of-type,
li:last-of-type{
text-decoration:line-through;
}
li:nth-child(even) {
background-color: #CCC;
}
li:nth-child(3) {
color: #CCC;
}
li:nth-of-type(odd) {
background-color: #FFF;
}
li:nth-of-type(4n) {
color: #C61800;
}
li:nth-of-type(3n-1) {
text-align: right;
}
li:only-of-type{width: 100%;}
li:nth-of-type(1):nth-last-of-type(2),
li:nth-of-type(2):nth-last-of-type(1){width: 50%;}
li:nth-of-type(1):nth-last-of-type(3),
li:nth-of-type(3):nth-last-of-type(1),
li:nth-of-type(2):nth-last-of-type(2){width: 33.33%;}
li:nth-of-type(1):nth-last-of-type(4),
li:nth-of-type(2):nth-last-of-type(3),
li:nth-of-type(3):nth-last-of-type(2),
li:nth-of-type(4):nth-last-of-type(1){width: 25%;}
div:not(.excludeMe)
Based on current state of UI
:enabled :disabled :checked
:invalid :required :optional
:in-range :out-of-range :read-only :read-write :default
Example:
input[type=checkbox]:checked + label {
color: red;
}
:lang :target :empty
link & user action pseudo-classes
:link :visited :hover :active :focus
:root
Selects the document root, which is <html>
::first-line
::first-letter
::selection (not in specification)
::before
::after
Pseudo-classes select elements that
already exist.
Pseudo-elements create "faux" elements you can style.
Use single colon because of IE
p:before {
content: "before content - ";
font-weight: bold;
}
p:after{
content: " - after content";
font-weight: bold;
}
<p>the content</p>
the content
<p>
<before>before content - </before>
the content
<after> - after content</after>
</p>
Try it out .thisSlide *::selection {
background-color: #990000;
color: #ffffff;
}
Prefix with -moz- for Firefox
Use single colon because of IE
.thisSlide *::selection {
background-color: #990000;
color: #ffffff;
}
For mobile but impacts desktop too:
.thisSlide {
-webkit-tap-highlight-color: #bada55;
-webkit-user-select: none;
-webkit-touch-callout: none;
}