<!-- example.html -->
<!DOCTYPE html>
<html>
<head>
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/normalize/3.0.3/normalize.min.css"
/>
<link rel="stylesheet" href="/styles/site.css" />
</head>
<body></body>
</html>
CSS Selector
: Applies styles to a specific DOM element(s), there are various types:
Type Selectors
: Matches by node name.Class Selectors
: Matches by class name.ID Selectors
: Matches by ID name.Universal Selectors
: Selects all HTML elements on a page.Attribute Selectors
: Matches elements based on the prescence or value of a given attribute. (i.e. a[title] will match all a elements with a title attribute)/* Type selector */
div {
background-color: #000000;
}
/* Class selector */
.active {
color: #ffffff;
}
/* ID selector */
#list-1 {
border: 1px solid gray;
}
/* Universal selector */
* {
padding: 10px;
}
/* Attribute selector */
a[title] {
font-size: 2em;
}
Class Selectors
.[class name]
Compound Class Selectors
h1
tags with the id of heading
.CSS Combinators
Be careful not to use too many of them as they will make your CSS far too complex.
Descendant Selectors
Direct Child Selectors
>
.Adjacent Sibling Selectors
+
symbol. h1 + h2 {
font-style: italic;
}
<h1>Big header</h1>
<h2>This one is styled because it is directly adjacent to the H1</h2>
<h2>This one is NOT styled because there is no H1 right before it</h2>
Pseudo-Classes
Pseudo-Class
: Specifies a special state of the seleted element(s) and does not refer to any elements or attributes contained in the DOM.
Selector:Pseudo-Class Name
or A:B
a:hover {
font-family: "Roboto Condensed", sans-serif;
color: #4fc3f7;
text-decoration: none;
border-bottom: 2px solid #4fc3f7;
}
active
: ‘push down’, when ele are activated.checked
: applies to things like radio buttons or checkbox inputs.disabled
: any disabled element.first-child
: first element in a group of children/siblings.focus
: elements that have current focus.hover
: elements that have cursor hovering over it.invalid
: any form elements in an invalid state from client-side form validation.last-child
: last element in a group of children/siblings.not(selector)
: elements that do not match the provided selector.required
: form elements that are required.valid
: form elements in a valid state.visited
: anchor tags of whih the user has already been to the URL that the href points to.Pseudo-Selectors
::after
::before
<style>
p::before {
background-color: lightblue;
border-right: 4px solid violet;
content: ":-) ";
margin-right: 4px;
padding-left: 4px;
}
</style>
<p>This is the first paragraph</p>
<p>This is the second paragraph</p>
<p>This is the third paragraph</p>
CSS Rules
CSS Rule
: Collection of single or compound selectors, a curly brace, zero or more propertiesCSS Rule Specificity
: Sometimes CSS rules will contain multiple elements and may have overlapping properties rules for those same elements - there is an algorithm in CSS that calculates which rule takes precendence.
The Four Number Calculation
: listed in increasing order of importance.<style>
.box {
width: 50px;
height: 50px;
border: 1px solid black;
}
.orange {
background-color: orange;
}
.yellow {
background-color: yellow;
border: 1px solid purple;
}
</style>
<div class="box yellow"></div>
<div class="box orange"></div>
purple border
.Typography
font-family
: change the font.
@import url('https://fonts.googleapis.com/css2?family=Liu+Jian+Mao+Cao&display=swap');
and pasting it st the top of your CSS file.font-size
: Changes the size of your font.
Absolute
: Pixels
, Points, Inches, Centimeters.Relative
: Em, Rem.
font-style
: Used to set a font to italics.font-weight
: Used to make a font bold.text-align
: Used to align your text to the left, center, or right.text-decoration
: Use to put lines above, through, or under text. Lines can be solid, dashed, or wavy!text-transform
: Used to set text to all lowercase, uppercase, or capitalize all words.Background-Images
Colors
a
is used to specify the alpha channel
.Borders
Shadows
box shadows
and text shadows
.