p { color: red }>npm test
) and check your work against (the AJAX project from
Tuesday is good practice)p { color: red }>@import
tag in order to import other CSS files into our own.@import url('https://fonts.googleapis.com/css2?family=Liu+Jian+Mao+Cao&display=swap');
@import 'other_styles.css';
p { color: red }>IDs
are unique, thus are considered highly specific since they always target one element.p { color: red }>score specificity
of selectors:
p { color: red }>IDs
? If no one, then continue evaluatingp { color: red }>classes
? If no one, then continue evaluatingp { color: red }>tags
? If no one, then continue evaluatingp { color: red }>last read
in the browser wins.<div id="main-header" class="header large on special otherClass">Some content here<div>
#main-header.large.on (1 ID, 2 classes, 0 tags) VS. div#main-header.header (1 ID, 1 class, 1 tag, last read(lower in the file))
h1 { (styles for all h1 elements) }
p { color: red }>#
before the ID:#main-header{ (styles to apply only to the element with the ID of "main-header") }
p { color: red }>.
before the class name:.large { (styles to apply to all elements with the class "large") }
p { color: red }>>
means a direct child. It will
not apply to deeply nested descendents, just those at the first nested level.
p { color: red }>ul > li
p { color: red }>space
in between selectors. Styles
will apply to ALL nested tags that match.
p { color: red }>ul li
<ul> <li>First</li> <li>Second</li> <div> <h3>Puppy!</h3> <img src="puppy.jpg" /> </div> <div> <li>Nested li</li> <li>Other nested li</li> </div> </ul>
p { color: red }>ul > li
will apply styles to the li with "First" and "Second", but
not the nested lis.p { color: red }>ul li
will apply styles to all four lis because it will target all descendents, not just
direct children.p { color: red }>comma
deliniated selectors. We can apply the same styles to
multiple elements by separating our selectors with commas.
p { color: red }>body, div, p, span, ul, li
p { color: red }>:hover
selector, for example, will apply the styles if the user's cursor is on top of
the element.p { color: red }>:hover
styles are no longer applied
and it goes back to the styling associated with the standard
p { color: red }>a
tag.<a href="https://google.com">Link</a>
a { color: #000fff; text-decoration: none; } a:hover { font-family: "Roboto Condensed", sans-serif; color: #4fc3f7; border: 2px solid #4fc3f7; }
p { color: red }>::before
and
p { color: red }>::after
pseudo elements, & Use the content
CSS property to define the content of an element:p { color: red }>::before
and
p { color: red }>::after
pseudo elements can be used in CSS in order to add content
at the very beginning or very end of an element.p { color: red }>content
property in the
CSS.<h1>test</h1>
h1::before { background-color: rebeccapurple; border-right: 1px solid yellow; content: 'This is a...'; margin-right: 4px; margin-left: 4px; } h1::after { background-color: lightblue; border-right: 1px solid violet; content: '...h1!'; margin-right: 4px; margin-left: 4px; }
p { color: red }>font-size
: size of lettersp { color: red }>font-weight
: boldness of lettersp { color: red }>font-style
: italicizationp { color: red }>font-family
: actualy font
p { color: red }>text-transform
: text casingp { color: red }>text-decoration
: underliningp { color: red }>text-align
: text justification (left, right, etc.)p { color: red }>color
css property changes the color of the text.p { color: red }>background-color
css property does just what it saysp { color: red }>rgb()
- takes in 3 integer values denoting levels of
p { color: red }>red, green and blue
, with
ranges of 0-255 each.p { color: red }>rgba()
- Same as above but with additional argument (the 'a', or 'alpha'
value) which represents how transparent the color will be (on a scale of 0-1, with 0 being
completely transparent and 1 being opaque).p { color: red }>border
property takes in three arguments:
p { color: red }>background-image
property, setting it's value to the url of a desired
image.p { color: red }>background-size
property will help us tell the browser how we want to scale/crop the
image to fill the space.
p { color: red }>contain
will scale the image to the bounds of the container, potentially leaving some
whitespace either vertically or horizontally so that the full image is seenp { color: red }>cover
will scale the image but will completely fill the container, potentially cropping
some portion of the image so that there is no whitespace#picture-here { <!-- absolute path --> background-image: url(https://appacademy.github.io/styleguide/assets/logo/logo-emblem-black-1000.png); <!-- relative path --> background-image: url(ajax.svg); background-size: cover; height: 100px; width: 100px; }
p { color: red }>browser compatibility
.p { color: red }>vh
or
p { color: red }>vw
), line
height (
p { color: red }>lh
), root element (
p { color: red }>rem
), etc.p { color: red }>rem
- relative to rootp { color: red }>em
- relative to parentp { color: red }>vh
- viewport heightp { color: red }>vw
- viewport widthp { color: red }>px
pixelp { color: red }>pt
pointp { color: red }>cm
centimeterp { color: red }>link
tag.p { color: red }>link
element has to have the
p { color: red }>rel
(relationship) and
p { color: red }>href
(hypertext
reference) attributes configured to indicate that this resource is a stylesheet and where it is coming from (a
relative or absolute reference):<link rel="stylesheet" href="file.css">
p { color: red }>content
CSS property to define the content of an elementp { color: red }>::before
and
p { color: red }>::after
pseudo elements, & Use the
content CSS property to define the content of an elementp { color: red }>content
lets us inject content into those pseudo elements, but if we wanted to adjust the content
of an element that already exists within the HTML, we would want to use JavaScript, such as by changing its
innerHTML property.p { color: red }>fetch
in order to send a request to a specific route on our server, along with an options
object to indicate the methods, headers, etc., that differ from the default values, a body with necessary data,
etc..p { color: red }>.then
on our call to
p { color: red }>fetch
, which allowed us to then
convert the response's JSON into a usable POJO when the response came back. The data inside of this object
is then accessible and used to manipulate the DOM.p { color: red }>GET
,
p { color: red }>PATCH
,
p { color: red }>POST
, and
p { color: red }>DELETE
.p { color: red }>.then
promise chains that we used in the project as well as
how we could convert them into an async/await format:// Using Promise chains for .then and .catch document.querySelector('#downvote').addEventListener('click', () => { fetch('http://localhost:3000/kitten/downvote', { method: 'PATCH' }) .then(handleResponse) // handleResponse defined below for reference .then(updateImageScore) // updateImageScore defined below for reference .catch(handleError); // handleError defined below for reference }); // Using async/await document.querySelector('#downvote').addEventListener('click', async () => { // Notice the async keyword on the callback definition! // We create a standard try/catch block try { // We await each asynchronous function call const resJSON = await fetch('http://localhost:3000/kitten/downvote', { method: 'PATCH' }); const resObj = await handleResponse(resJSON); // updateImageScore is synchronous, so we do not have to await its response updateImageScore(resObj); } catch (e) { handleError(e) } }); // Functions used above, for reference const handleResponse = (response) => { stopLoader(); clearError(); if (!response.ok) { throw response; } return response.json(); }; const handleError = (error) => { if (error.json) { error.json().then((errorJSON) => { document.querySelector('.error').innerHTML = `Error occured: ${errorJSON.message}`; }); } else { console.error(error); alert('Something went wrong. Please try again!'); } }; const updateImageScore = (data) => { const { score } = data; document.querySelector('.score').innerHTML = score; };
p { color: red }>all
- we are not distinguishing between the following (this is default)p { color: red }>print
- i.e. anytime a document is set to print mode, with intention of printing.p { color: red }>screen
- phones, tablets, computers, smart devices, etc.p { color: red }>speech
- for use with speech synthesizersp { color: red }>@media
keyword. We can combine multiple features and even include the media type by using the
p { color: red }>and
operator:html { background-color: white; color: #333333; } @media screen and (min-width: 301px) and (max-width: 600px) { html { background-color: #333333; color: white; } }
p { color: red }>aspect-ratio
: The ratio of width-to-height of the user's viewport (for example, a window
that is 1600 pixels wide and 800 pixels tall will have an aspect ratio of 2). We will most often use this
with a
p { color: red }>min-
or
p { color: red }>max-
prefix instead of setting one specific value.p { color: red }>height
: the height of the viewport, typically in pixels. Most often used with a
p { color: red }>min-
or
p { color: red }>max-
prefix to set a bounds instead of a specific value.p { color: red }>width
: the width of the viewport, typically in pixels. Most often used with a
p { color: red }>min-
or
p { color: red }>max-
prefix to set a bounds instead of a specific value.p { color: red }>orientation
: An indicator of whether our viewport is wider than it is tall
(
p { color: red }>landscape
) or taller than it is wide (
p { color: red }>portrait
). Since we are just using these
exact values, we do not use any prefixes.p { color: red }>display
property to
p { color: red }>none
, or if we have a color background we can change it to white for
p { color: red }>print
media, etc.
p { color: red }>product-index
container so the items appear in a verticle fashion for a viewport width less than or
equal to 300px:.product-index { display: flex; } .product-index__item { background-color: blue; }
@media screen and (max-width: 300px) { .product-index { flex-direction: column; } }
padding and margins work in the box model
p { color: red }>padding
- the innermost part of the box model -- creating space around an element's
content before its border.p { color: red }>margin
- the space between one html element and another html elementp { color: red }>box-sizing
property will also affect how these values are calculated.
p { color: red }>content-box
, setting a width or height on an element is only considering
the content itself. Any padding and border that we add on is going to be in addition to this
specification.
p { color: red }>border-box
, setting a width or height on an element is going to consider
the content, padding, and border as part of that width or height calculation.
the browser positions a fixed positioned element
p { color: red }>position: fixed
- always relative to the document, not any particular parent, and are
unaffected by scrolling. It will always show up at that exact location on the screen, no matter where the
user is scrolled to.the browser positions a relatively positioned element
p { color: red }>position: relative
- positioned relative to where it would normally be located; i.e. the
element is still in the flow of the document, but now left/right/top/bottom/z-index will affect how it is
actually displayed.the browser positions absolutely positioned elements with and without a relatively positioned parent element
p { color: red }>position: absolute
- the element is removed from the flow of the document and other elements
will behave as if it's not even there. If its positioning is affected by a left/right/top/bottom
property, it will use its closest
p { color: red }>position: relative
parent as the starting point. If no parent
is positioned relatively it will use the document in general as its reference.the browser positions a static positioned element
p { color: red }>position: static
- this is the default positioning, so you won't see it written out that
often. Elements are in their normal page flow, one after the other. The positioning properties
left/right/top/bottom/z-index do not affect statically positioned elements. If we want to use these
properties we would need to change the positioning to one of the previously mentioned values.p { color: red }>box-sizing
is set to
p { color: red }>content-box
, this will extend our overall
width/height. When it is set to
p { color: red }>border-box
, this will eat into our content area.p { color: red }>background-color
that affect our content area will generally also apply to
our padding.p { color: red }>-left
,
p { color: red }>-right
,
p { color: red }>-top
, and
p { color: red }>-bottom
suffixes on
p { color: red }>padding
and
p { color: red }>margin
to specify that specific side.
p { color: red }>margin-right: 5px
will add a 5px margin ONLY to the right side.p { color: red }>margin: 5px
will add a 5px margin on all sidesp { color: red }>margin: 5px 10px
will add a 5px top and bottom margin and a 10px right and left margin.
p { color: red }>margin: 5px 10px 15px 10px
will add a 5px top margin, 10px right margin, 15px bottom
margin, and 10px left margin.p { color: red }>position: fixed
with a specific value for
p { color: red }>top
and
p { color: red }>right
properties to
set it in that corner.p { color: red }>position: relative
and have the child
p { color: red }>position: absolute
with a
p { color: red }>right: 20px
property in order to set it positioned to that relative parent.p { color: red }>inline
include
p { color: red }>span
,
p { color: red }>a
,
p { color: red }>input
,
p { color: red }>button
,
p { color: red }>img
tags, etc.p { color: red }>inline
display values will result in the element being displayed next to each other in a single
line until it fills up the available space.p { color: red }>width
and
p { color: red }>height
properties do not affect how the element is displayed.p { color: red }>padding
,
p { color: red }>margin
, and
p { color: red }>border
can still be used, but will not affect
other
p { color: red }>inline
elements. For example, setting a margin of 100px will still have the other inline
elements display directly next to it, but the block element that comes later on in the document on its own line
will still be pushed down.p { color: red }>block
include
p { color: red }>div
,
p { color: red }>p
, headers like
p { color: red }>h1
,
p { color: red }>ul
,
p { color: red }>li
tags, etc.p { color: red }>block
display values will result in elements being displayed on a new line.p { color: red }>width
and
p { color: red }>height
properties are respected.p { color: red }>z-index
can be useful in setting an element on different layers of the page, its third
dimension. These different layers are purely visual, they do not affect the layout and positioning of other
elements.p { color: red }>z-index
means we want that element on top. We can think of it as the line coming
straight out of the screen. We want that element closer to the user.p { color: red }>z-index
means we want the element behind other elements, pushed away from the user.
p { color: red }>container
's height/width will adjust to the viewport.p { color: red }>flex
property to specify grow, shrink, and basis values.p { color: red }>flex
property is a combination of three different properties:
p { color: red }>flex-grow
,
p { color: red }>flex-shrink
, and
p { color: red }>flex-basis
.p { color: red }>flex-grow
:
p { color: red }>flex-grow
property to different values for elements within the same container sets
up a ratio for how much of the extra space should be alotted to the different elements to grow into.p { color: red }>flex-shrink
:
p { color: red }>flex-grow
, this property determines what factor the element should shrink by when
the container is not large enough to fit all elements.p { color: red }>flex-shrink
value, they will all shrink at the same rate.
Larger values will shrink at a faster rate than smaller values.p { color: red }>flex-basis
:
p { color: red }>content
to assign the size required to fit all of the element's content.
p { color: red }>flex-direction
property to direct the layout of the contentp { color: red }>flex-direction
.p { color: red }>row
, but we can use
p { color: red }>column
to display our
content vertically.p { color: red }>flex-wrap
property to affect the wrap of content layout within an element using flexible
box layoutp { color: red }>flex-wrap: wrap
.p { color: red }>nowrap
is the default valuep { color: red }>wrap-reverse
will stack our rows or columns in the reverse order (our second row will display on
top or our second column will display to the left, for example)p { color: red }>align-self
,
p { color: red }>justify-content
, and
p { color: red }>align-items
to change the way that
children elements are laid out in a flexible box layoutp { color: red }>justify-content
is always concerned with positioning ALONG the main axis.
p { color: red }>justify-content
will determine how the elements
are positioned horizontally along that row.p { color: red }>justify-content
will determine how the elements
are positioned vertically along that column.p { color: red }>align-items
is always concerned with positioning ACROSS the main axis.
p { color: red }>align-items
will determine how the elements are
positioned vertically across that row.p { color: red }>align-items
will determine how the elements are
positioned horizontally across that column.p { color: red }>align-self
allows us to selectively tell an element that we want it to align itself differently
compared to the standard
p { color: red }>align-items
rule.
p { color: red }>align-self: flex-start
, for example, which would keep all of
the other elements in line and just bump this element up to the top of the row.p { color: red }>order
property to change the order in which elements will appear in a flexible box layout
p { color: red }>order
can be used to rearrange individual elementsp { color: red }>order: -1
. If
all of the other elements are left to default (0), it will be the lowest value and be shown first.p { color: red }>grid-template-columns
,
p { color: red }>grid-template-rows
, and
p { color: red }>grid-template
properties to specify the layout of the grid using relative and absolute measuresp { color: red }>grid-template-columns
allows us to take in any number of arguments to signify the dimensions for
the corresponding column. Passing two values means we are creating two columns for our grid, for example.p { color: red }>grid-template-rows
allows us to take in any number of arguments to signify the dimensions for the
corresponding row. Passing two values means we are creating two rows for our grid, for example.p { color: red }>grid-template
is shorthand to allow us to define rows and columns at once. We do so by providing
our row values, then a
p { color: red }>/
then the column values, such as
p { color: red }>grid-template: 100px 1fr / 50px 200px 50px
. We can also provide additional arguments to for area
names, with many additional optional syntaxes. Personally I think these can get confusing to parse, but if
you're curious, take a look at the MDN docs: https://developer.mozilla.org/en-US/docs/Web/CSS/grid-template
p { color: red }>grid-template-areas
to label areas of a grid and
p { color: red }>grid-area
to assign an element
to the areap { color: red }>grid-template-areas
property on the container..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"; }
p { color: red }>grid-area
property on an individual element to
add it to that section of the grid:.item-1 { grid-area: header; } .item-2 { grid-area: main; } .item-3 { grid-area: sidebar; } .item-4 { grid-area: footer; }
p { color: red }>column-gap
,
p { color: red }>row-gap
, and
p { color: red }>gap
(previously
p { color: red }>grid-column-gap
,
p { color: red }>grid-row-gap
, and
p { color: red }>grid-gap
) to set the
"gutter" areas between elements in a grid layoutp { color: red }>gap
properties can be used to define space that we want to maintain between our rows and
columns.p { color: red }>grid-column-start
/
p { color: red }>grid-column-end
and
p { color: red }>grid-row-start
/
p { color: red }>grid-row-end
to create spans across multiple columns and rows with
positive integers, negative integers, and in conjunction with the "span" operatorp { color: red }>-start
values are the grid lines that we want our element to begin at. The left-most and
top-most grid lines (outside borders) begin at 1 and count upwards as we move right and down the grid.p { color: red }>-end
values are where the element will stretch to.p { color: red }>span
to indicate we want to
continue across a certain number of rows/columns. For example,
p { color: red }>grid-column-end: span 2
will go
across two columns instead of specifying a specific column number.p { color: red }>grid-column
and
p { color: red }>grid-row
to define how an
element will span a grid layoutp { color: red }>grid-column
is a combination of
p { color: red }>grid-column-start and grid-column-end
, allowing us
to provide both values in one line, separated by
p { color: red }>/
.
p { color: red }>grid-column: 1 / 3;
will assign this element to stretch from column 1 to 3 (the first two
columns of the graph.)p { color: red }>grid-row
is a combination of
p { color: red }>grid-row-start and grid-row-end
, allowing us to provide
both values in one line, separated by
p { color: red }>/
.
p { color: red }>grid-row: 4 / span 4;
will assign this element to stretch from row 4, spanning the next four
rows.p { color: red }>order
property to change the default order in which items are laid outp { color: red }>fr
indicates the fraction of available spacep { color: red }>grid-template-rows: 50px 2fr 1fr
. This will always take 50px for the first
row, then divide up the rest based on the fractions.p { color: red }>justify-items
,
p { color: red }>align-items
,
p { color: red }>justify-content
and
p { color: red }>align-content
to layout items in each grid areap { color: red }>justify-items
and
p { color: red }>align-items
will position items within the respective section of
the grid.
p { color: red }>justify-items
will position the items horizontally within the boxp { color: red }>align-items
will position the items vertically within the boxp { color: red }>row
direction.p { color: red }>justify-content
and
p { color: red }>align-content
will position the grid itself within the
container, assuming it does not fill the full container.
p { color: red }>:hover
pseudo-class to an element when the user's
pointer is on it.p { color: red }>none
to
p { color: red }>block
to make a drop-down menu appear.p { color: red }>transition
property to show animated changes due to class and pseudo-class
CSS rule applicationp { color: red }>transition-property
p { color: red }>all
, meaning every difference in style will be affected by these transition
rules.p { color: red }>transition-duration
p { color: red }>transition-timing-function
p { color: red }>ease
, which shows a slow transition at the beginning, speeds up in the middle,
then slows down at the end.p { color: red }>linear
,
p { color: red }>ease-in
, and
p { color: red }>ease-out
. These can
become more complicated if you use a custom function with
p { color: red }>cubic-bezier
or
p { color: red }>steps
.
p { color: red }>transition-delay
p { color: red }>transition
is shorthand for
p { color: red }>transition-property
,
p { color: red }>transition-duration
,
p { color: red }>transition-timing-function
, and
p { color: red }>transition-delay
.nav__button--active:hover { transition: background-color 2s, color 1s 1s; }
p { color: red }>overflow
,
p { color: red }>overflow-x
, and
p { color: red }>overflow-y
properties to
effect clipping and scrolling on elementsp { color: red }>overflow
property will account for any extended content, horizontal or vertical. If we'd
like to distinguish, we can use
p { color: red }>overflow-x
and
p { color: red }>overflow-y
.p { color: red }>overflow: auto
- hides any content that exceeds the container size, adding a scroll bar if needed
to show that content.p { color: red }>overflow: scroll
- always adds a scroll bar, even if it would not be needed with the content.
p { color: red }>overflow: hidden
- clips any content that exceeds the container size. No scroll is added, so the
user will not to see anything that extends beyond the container.p { color: red }>overflow: visible
- the content is allowed to extend beyond the container without clipping or
scrolling, potentially spilling into other elements.p { color: red }>.block__elem--dark-mode
class that is added in response to that click that alters
the color.p { color: red }>.bag__add-btn--disabled
class that gets added to our button on the eighth addition that sets our cursor property to
p { color: red }>not-allowed
, helping the user understand they should not click the button any more./* Here we have a block called "nav" that we have associated with a "dark" modifier */ /* Use modifier class name as selector. */ .nav--dark { } /* We are selecting the nested "list-container" element when our "nav" block has the "dark" modifier */ /* Alter elements based on a block-level modifier. */ .nav--dark .nav__list-container { } /* We are selecting the "list-container" element of the "nav" block when this element has been given the "shadow" modifier */ /* Element modifier: */ .nav__list-container--shadow { }
p { color: red }>.nav__list-container--shadow
is all one class that we created in order to make styles specifically
for adding a shadow on the list container.