<!-- 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
.
AJAX
: Stands for Asynchronous Javascript and XML.Classic Full Page Reloads
At a high level, AJAX is simply a group of different technologies that work together to allow a website to communicate with a server in the bg without requiring the website to need to reload.
Nowadays, XML has more or less been replaced by JSON.
AJAX introduces more complexity but the benefit is an improved user experience.
AJAX allows you to keep the user in their current context.
There are JS libraries that make using AJAX a lot easier (i.e. JQuery)
Fetch
is used to make HTTP Requests, it uses Promises to handle the async nature of HTTP requests and responses.GET
: Request used to retrieve information from the server.fetch("https://jservice.xyz/api/games")
.then(function (res) {
console.log("response: ", res);
return res.json();
})
.then(function (data) {
console.log("data:", data);
});
options
argument, which can be used to add additional header information.POST
: Used to create data on the server.fetch("https://jservice.xyz/api/categories", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
title: "ACTORS & THEIR FILMS",
}),
})
.then(function (res) {
console.log(res);
if (!res.ok) {
throw Error(res.statusText);
}
return res.json();
})
.then(function (data) {
console.log(data);
})
.catch(function (error) {
console.log(error);
});
ok
key inside of the Response Object, and if the key is false then the fetch can properly handle the error.ok
key and place a catch error handler at the end of the promise chain.AJAX Broken Down
<button class="want-to-read">Want to Read</button>
<script async>
document.querySelector(".want-to-read").addEventListener("click", function() {
fetch(`https://api.goodreads.com/books/${BOOK_ID}/update-status`, {
method: "PATCH", // using PATCH since we'll just be modifying the book's status
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
status: "Want to Read"
})
})
.then(function(res) {
if (!res.ok) {
throw Error(res.statusText); // handle any potential server errors
}
return res.json(); // extract JSON from the response
})
.then(function(data) {
document.querySelector(".want-to-read").innerHTML = "✓ Want To Read";
})
.catch(function(error) {
const errorMessage = document.createElement("p");
errorMessage.appendChild(
document.createTextNode("Something went wrong. Please try again!")
);
// This example appends an error message to the body for simplicity's sake.
// Please do not copy this kind of DOM manipulation in your own projects:
document.querySelector("body").appendChild(errorMessage);
});
});
</script>
When we first send out the event listener and fetch with filled out options this is ths segment where we are conducting the Javascript Call
.
When the request is sent out it is the arrow leading from the AJAX engine to the Web Server.
The arrow from the Web Server back to the AJAX engine is the response from the Server in either XML or JSON format.
The response is handled within the AJAX engine and returns the new HTML & CSS for the UI.
ok
response is received so that potentials errors can be handled correctly.# Notes |
## The Box Model |
- Box Model : A concept that basically boils down that every DOM element has a box around it. |
> Imagine a gift, inside is the gift, wrapped in foam all around (padding), and the giftbox outside of it (border) and then a wrapping paper on the giftbox (margin). |
- For items that are using block as it’s display, the browser will follow these rules to layout the element: - The box fills 100% of the available container space. - Every new box takes on a new line/row. - Width and Height properties are respected. - Padding, Margin, and Border will push other elements away from the box. - Certain elements have block as their default display, such as: divs, headers, and paragraphs. |
- For items that are using inline as it’s display, the browser will follow these rules to layout the element: - Each box appears in a single line until it fills up the space. - Width and height are not respected. - Padding, Margin, and Border are applied but they do not push other elements away from the box. - Certain elements have inline as their default display, such as: span tags, anchors, and images. |
Standard Box Model vs Border-Box |
- As per the standard Box Model, the width and height pertains to the content of the box and excludes any additional padding, borders, and margins. |
- This bothered many programmers so they created the border box to include the calculation of the entire box’s height and width. |
Inline-Block |
- Inline-block uses the best features of both block and inline . - Elements still get laid out left to right. - Layout takes into account specified width and height. |
Padding |
- Padding applies padding to every side of a box. It is shorthand for four padding properties in this order: padding-top , padding-right , padding-bottom , padding-left (clockwise!) |
Border |
- Border applies a border on all sides of an element. It takes three values in this order: border-width , border-style , border-color . - All three properties can be broken down in the four sides clockwise: top, right, bottom, left. |
Margin |
- Margin sets margins on every side of an element. It takes four values in this order: margin-top , margin-right , margin-bottom , margin-left . - You can use margin: 0 auto to center an element. |
position
property allows us to set the position of elements on a page and is an integral part of creatnig a Web page layout.static
, relative
, absolute
, fixed
, sticky
.static
) is used with: top
, right
, bottom
, and left
to position an element on a page.Static Positioning
Relative Positioning
#pink-box {
background-color: #ff69b4;
bottom: 0;
left: -20px;
position: relative;
right: 0;
top: 0;
}
Absolute Positioning
.container {
background-color: #2b2d2f;
position: relative;
}
#pink-box {
position: absolute;
top: 60px;
}
.container {
background-color: #2b2d2f;
position: relative;
}
#pink-box {
position: absolute;
top: 60px;
}
#blue-box {
position: absolute;
}
.container {
background-color: #2b2d2f;
position: relative;
}
#pink-box {
background-color: #ff69b4;
bottom: 60px;
position: absolute;
}
.container {
background-color: #2b2d2f;
}
#pink-box {
background-color: #ff69b4;
bottom: 60px;
position: absolute;
}
Fixed Positioning
Sticky Positioning
Flexbox is a CSS module that provides a convenient way for us to display items inside a flexible container so that the layout is responsive.
Using Flexbox
Flexbox automatically resizes a container element to fit the viewport size without needing to use breakpoints.
Flexbox layout applies styles to the parent element, and it’s children.
.container {
display: flex; /*sets display to use flex*/
flex-wrap: wrap; /*bc flex tries to fit everything into one line, use wrap to have the elements wrap to the next line*/
flex-direction: row; /*lets us create either rows or columns*/
}
flex-flow
can be used to combine wrap and direction.justify-content
used to define the alignment of flex items along the main axis.align-items
used to define the alignment on the Y-axis.align-content
redistributes extra space on the cross axis.
By default, flex items will appear in the order they are added to the DOM, but we can use the order
property to change that.
flex-grow
: dictates amount of avail. space the item should take up.flex-shrink
: defines the ability for a flex item to shrink.flex-basis
: Default size of an element before the remaining space is distributed.flex
: shorthand for grow, shrink and basis.align-self
: Overrides default alignment in the container.Bootstrap vs CSS Grid
.grid-container {
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-template-rows: auto;
grid-template-areas:
"header header header"
"main . sidebar"
"footer footer footer";
grid-column-gap: 20px;
grid-row-gap: 30px;
justify-items: stretch;
align-items: stretch;
justify-content: stretch;
align-content: stretch;
}
.item-1 {
grid-area: header;
}
.item-2 {
grid-area: main;
}
.item-3 {
grid-area: sidebar;
}
.item-4 {
grid-area: footer;
}
repeat
, fractions.Grid Template Areas
gives us a handy way to map out and visualize areas of the grid layout.Grid Gaps
can be used to create ‘gutters’ between grid item.s
The way we have defined our grid with grid-templates
and areas
are condidered explicit.
We can also implicitly
define grids.
.grid-container {
display: grid;
grid-template-columns: 100px 100px 100px 100px;
grid-template-rows: 50px 50px 50px;
grid-auto-columns: 100px;
grid-auto-rows: 50px;
}
Spanning Columns & Rows
We can use the following properties to take up a specified num of cols and rows.
grid-column-start
grid-column-end
grid-row-start
grid-row-end
All four properties can take any of the following values: the line number, span #, span name, auto.
.item-1 {
grid-row-start: row2-start; /* Item starts at row line named "row2-start" */
grid-row-end: 5; /* Item ends at row line 5 */
grid-column-start: 1; /* Item starts at column line 1 */
grid-column-end: three; /* Item ends at column line named "three" */
}
.item-2 {
grid-row-start: 1; /* Item starts at row line 1 */
grid-row-end: span 2; /* Item spans two rows and ends at row line 3 */
grid-column-start: 3; /* Item starts at column line 3 */
grid-column-end: span col5-start; /* Item spans and ends at line named "col5-start" */
}
Grid Areas
Justify & Align Self
Justify Self is used to align self on the row.
# Notes |
## CSS Hover Effect and Handling Overflow |
css .btn { background-color: #00bfff; color: #ffffff; border-radius: 10px; padding: 1.5rem; } .btn--active:hover { cursor: pointer; transform: translateY(-0.25rem); /* Moves our button up/down on the Y axis */ } |
- The Pseudo Class Selector hover activates when the cursor goes over the selected element. |
Content Overflow |
- You can apply an overflow content property to an element if it’s inner contents are spilling over. - There are three members in the overflow family: - overflow-x : Apply horizontally. - overflow-y : Apply vertically. - overflow : Apply both directions. |
Defining Transitions
transition-property
: specifies the name of the CSS property to apply the transition.transition-duration
: during of the transition.transition-delay
: time before the transition should start.Examples :
#delay {
font-size: 14px;
transition-property: font-size;
transition-duration: 4s;
transition-delay: 2s;
}
#delay:hover {
font-size: 36px;
}
.box {
border-style: solid;
border-width: 1px;
display: block;
width: 100px;
height: 100px;
background-color: #0000ff;
transition: width 2s, height 2s, background-color 2s, transform 2s;
}
.box:hover {
background-color: #ffcccc;
width: 200px;
height: 200px;
transform: rotate(180deg);
}
block
, element
, modifier
.Block
Element
BEM Example
<form class="form form--theme-xmas form--simple">
<input class="form__input" type="text" />
<input class="form__submit form__submit--disabled" type="submit" />
</form>
/* block selector */
.form {
}
/* block modifier selector */
.form--theme-xmas {
}
/* block modifier selector */
.form--simple {
}
/* element selector */
.form__input {
}
/* element selector */
.form__submit {
}
/* element modifier selector */
.form__submit--disabled {
}