James Sherry PRO
Web Development Tutor and Co-Founder of { The Jump } Digital School
Progressive Enhancement
Graceful Degradation
<!DOCTYPE html>
<html>
<head>
<title>My Page</title>
<!-- RESET GOES HERE -->
<!-- THIRD-PARTY STYLESHEETS GO HERE -->
<style>
/* CSS GOES HERE */
</style>
</head>
<body>
...
<!DOCTYPE html>
<html>
<head>
<title>My Page</title>
<!-- RESET GOES HERE -->
<!-- THIRD-PARTY STYLESHEETS GO HERE -->
<!-- Now your styles -->
<link rel="stylesheet" href="/styles/styles.css">
</head>
<body>
...
All CSS style sheets are case-insensitive, except for parts that are not under the control of CSS. For example, the case-sensitivity of values of the HTML attributes, including "id" and "class", of font names, and of URIs lies outside the scope of this specification. Note in particular that element names are not case-insensitive in HTML, but case-sensitive in XML.
/* This is a comment */
/*************************
* SO IS THIS
**************************/
/* Comments can be used to organise */
/* Main Nav */
nav {
font-weight: bold;
}
/* Product grid */
.product {
border: 1px solid #000;
}
`cmd + /` (or `ctrl + /` on windows) to toggle
h1 {
color: red;
}
<!-- html fragment: for exercise only -->
<h1>My Red Heading</h1>
N.B. You can put more than one declaration in a block.
Can include:
html {
box-sizing: border-box;
}
*,
*::before,
*::after {
box-sizing: inherit;
}
:root {
--base-color: white;
}
p {
margin-bottom: 1em;
}
.section-title {
// ...
}
#special {
...
}
matches
<div id="special">.....</div>
a[href^="mailto"] {
...
}
img[alt~="person"][src*="lorem"] {
...
}
.intro.logo {
matches
<? class="logo intro other">.......</?>
[src^="https"].profile {
matches
<? src="https://...." class="profile">....</?>
/* <p class="intro"> or <p class="intro hello">*/
p.intro {
color: green;
}
Useful in some circumstances, but usually bad practice:
a:hover {
...
}
input:focus {
...
}
tr:nth-child(3n+1) {
...
}
More here
p:not(.special) {
...
}
^^ That's ALL the paragraphs, but NOT the ones with a class of special
p::selection {
background-color: yellow;
}
label::after {
content: '*';
color: red;
}
More here
(Selector chains should be ~3 selectors max in length!)
ul li {
border: 1px solid;
}
.product > ul {
...
}
input:valid + label {
color: green;
}
input:valid ~ label {
color: green;
}
/* All the <a>s and the <span>s */
a,
span {
color: green;
}
:is(section, article, aside, nav) :is(h1, h2, h3, h4, h5, h6) {
color: #BADA55;
}
/* ... which would be the equivalent of: */
section h1, section h2, section h3, section h4, section h5, section h6,
article h1, article h2, article h3, article h4, article h5, article h6,
aside h1, aside h2, aside h3, aside h4, aside h5, aside h6,
nav h1, nav h2, nav h3, nav h4, nav h5, nav h6 {
color: #BADA55;
}
stylesheet1.css
stylesheet2.css
h1 {
color: red;
text-decoration: underline;
}
h1 {
color: blue;
}
The declaration from stylesheet2.css will win on color, and the underline from stylesheet1.css will still count
within the same or different stylesheets:
stylesheet1.css
stylesheet2.css
header h1 {
color: red;
}
h1 {
color: blue;
}
Now the heading will be red, even though blue came afterwards, because the selector is more specific
within the same or different stylesheets:
Credit: Chris Coyier @css-tricks.com (https://css-tricks.com/specifics-on-css-specificity/)
Credit: Chris Coyier @css-tricks.com (https://css-tricks.com/specifics-on-css-specificity/)
Credit: Chris Coyier @css-tricks.com (https://css-tricks.com/specifics-on-css-specificity/)
Credit:
Estelle Weyl (http://www.standardista.com)
By James Sherry
Intro to CSS