Home

Cascading Style Sheets(CSS)

A language used to customize the styling of HTML and/or XML.

selector{
    property: property value;
}
/* Comments */
/*
    The setting value order is in {top/bottom right/left} or
    {top right bottom left}
*/

Miscellaneous

Background

CSS Name What it does
background Combination of background properties.
background-color Sets the background color.
background-image: url(‘file path’); Sets a background image.
background-size Sets the how the background image is shown. Usually cover
background-repeat Sets background image repeating property. Usually no-repeat
background-position Sets the position of the background image. Usually center center
background: linear-gradient(direction, color stop 1, color stop 2, …) Creates a gradient that can be between 2 or more colors.

Linear Gradient

Text

CSS Name What it does
font-size Changes size of text.
color Changes color of the text.
font-weight Changes the thickness or boldness of the text characters.
text-align Aligns the text itself. Not its container.
font-style Sets italics, normal, or oblique.
text-transform Used to control the capitalization. none, capitalize, uppercase, lowercase, initial, inherit.
text-decoration Changes underline, overline, line-through, or other effects.
font-family Sets the font of the text. Apply multiple fonts for backups. sarif is common on almost all devices.
line-height Specifies the height of the line. This includes vertical spacing between lines and highlighting height.
user-select Controls if the user can select/highlight the text.

Sizing

CSS Name What it does
width Changes width of the content.
height Changes height of the content.
border-radius Set equal width and height and border-radius to 50% to make it a circle.
max-width Sets the maximum width an element can have. Can’t go over.
min-width Sets the minimum width an element can have. Can’t go under.

In order for a percentage height or width to work properly, the parent container needs to have a specified height.

Box Sizing

box-sizing: is used to control how the width and height are calculated, taking into account the element’s padding and border.

   
content-box The default value. width/height changes the content.
border-box width/height changes the content, padding, and border.

Margin/Padding/Border/Outline

-----------------------------------
/             Margin              \
/  -----------------------------  \
/  /          Outline          \  \
/  /  -----------------------  \  \
/  /  /       Border        \  \  \
/  /  /  -----------------  \  \  \
/  /  /  /    Padding    \  \  \  \
/  /  /  /  -----------  \  \  \  \
/  /  /  /  / Content \  \  \  \  \
/  /  /  /  -----------  \  \  \  \
/  /  /  -----------------  \  \  \
/  /  -----------------------  \  \
/  -----------------------------  \
-----------------------------------
border: {size} {style} {color};

Border Styles

border-style: {type}
border-top-style: {type}
border-right-style: {type}
border-bottom-style: {type}
border-left-style: {type}

Positioning

position: {type}

Static

Default behavior.

Relative

Relative to the normal position. Allows for top, right, bottom, left. Doesn’t change the other elements. Still in the document flow.

Absolute

Moves relative to the nearest position ancestor or the body if none is specified. In order to position to the nearest ancestor it needs to have a position: relative. Take it out of the flow of the document. Other elements ignore it.

Fixed

Moves relative to the view port.

Sticky

Absolute positioning, but will stick to the side of the screen if the content moves.

Display

display: {display name}

display name What it does
inline Makes element inline. Stays on the same line.
block Makes element a block. Puts element on a new line.
none Hides an element. Doesn’t take up space.
inline-block Block of text but stuff can be on either side. Not styled the same as the other inline stuff.
initial Reverts the display to its defualt state.

Flex

Put display: flex; on parent.

It is recommended to use flex only when you need 1 column/row

Each wrap creates a new item. The content includes all the items/lines.

    On parent or On child
flex-wrap: Forces elements to the next line if they don’t fit. On parent
justify-content: How content are spaced on the main axis. Applies to multiple items. On parent
justify-items: Aligns the main axis multiple lines of flex items created by flex-wrap. On parent
justify-self: Aligns self on main axis. On child
align-content: How items are spaced on the cross axis. Applies to multiple items. On parent
align-items: Aligns the cross axis items/lines created by flex-wrap On parent
align-self: Align self on cross axis. On child
flex-direction: Change the direction which flex is. By default it is row On parent
order: Changes the ordering priority of an element. On child
    On parent or On Child
flex: {flex-grow} {flex-shrink} {flex-basis} flex-basis is the initial size of the flex item before any available space is distributed. On child

flex-wrap

flex-direction

Can change the main axis and the cross axis.

justify/align -content/-items/-self

Flex box froggy Game - https://flexboxfroggy.com/

Grid

Similar to flex-box/display flex, but for 2 dimensions instead of 1.

Put display: grid on parent.

   
grid-template-columns: Sets the columns of the grid.
grid-template-rows: Sets the rows of the grid.
grid-auto-rows: Determines the size of all rows added after the template rows.
grid-gap: Sets the size of the gaps between both rows and columns.
grid-row-gap: Sets the size of the gaps between rows.
grid-columns-gap: Sets the size of the gaps between columns.
grid-template-areas: Used to define named grid areas in a grid container.

Example:

.container{
    grid-template-columns: 3;
}
.element1{
    grid-column: span 2;
}
.element1{
    grid-column: span 1;
}

Grid Template

div{
    display: grid;
    grid-template-columns: 2fr 1fr;
}
Grid Template Areas

Used to define named grid areas in a grid container.

div{
    grid-template-areas:
        "header header"
        "sidebar content"
        "sidebar content"
}

div div{
    grid-area: header; /*Sets the child div as the header */
}

Overflow

Overflow controls what happens when content overflows the boundaries. Use overflow: property value to set the overflow type.

property value Description
visible Overflow the content without clipping and potentially covering other content.
hidden Overflow hidden
scroll Always shows the scrollbar
auto Only shows the scroll bar when contents overflow.

Visibility

visibility: {visibility name}

visibility name What it does
visible Default.
hidden Hides an element. Takes up space.

Units

   
px pixles
% Size of parent element
vw Screen width
vh Screen height
rem Relative to root font size usually defined by the browser.

Adaptive Screen Width

// Change css when screen width is 1000px or less
@media screen and (max-width: 1000px){}
or
@media screen and (width < 1001px) {}
    // <= doesn't work

// Only between 1000px and 800px inclusive
@media screen and (max-width: 1000px) and (min-width: 800px){}

You can also do min-height or max-height

Transform

transform: {function}

Transform Functions

Pseudo Classes/Elements

Pseudo Classes

Pseudo classes allow you to style an element based on a specific state or condition.

Pseudo classes take the format of {selector}:{pseudo-class}

These are the most common pseudo classes.

Custom JavaScript Pseudo Class

The JavaScript is used to create a custom state or condition.

<!-- HTML -->
<div class="my-class-element"/>

// JavaScript
let myClassElements = document.querySelectorAll(".my-class-element")

myClassElements.forEach((element) => {
    // Custom state or condition.
    element.addEventListener("click", () => {
        element.classList.toggle("custom-pseudo-class")
    })
})

/* CSS */
.my-class-element:custom-pseudo-class{
    /* Styling */
}

Pseudo Elements

In order for the pseudo elements to show the content has to be set. Usually content: ""

Pseudo elements have the format of {selector}::{pseudo-element-name}

These are the most common pseudo element.

CSS Reset

The browser applies some CSS by default. The CSS reset is used to remove this default CSS so that your website will look the same on all browsers.

Your custom CSS has to be applied after the CSS reset so that the custom CSS overwrites the CSS reset.

CSS Selectors

CSS selectors are used to select an element in order to apply styling to it.

   
.class Selects elements with class=”class”
.class1.class2 Selects elements with both class1 and class2
#id Selects elements with id=”id”
element Selects all elements of that element
element.class Selects all elements of that element with class
element, element Selects all elements of both elements
* Selects all elements of any type

CSS Combinators

CSS combinators are special characters that are used to select specific elements with relations to another element.

   
space descendant selector
> child selector
+ selects an element that directly follows another element
~ general sibling selector
/* Example */
    /* HTML */
<div>
   <p>Par 1</p>
   <div>
      <p>Par 2</p>
   </div>
</div>
<p>Par 3</p>
<p>Par 4</p>

    /* CSS */
div p       /* Selects Par 1 and Par 2 */
div > p     /* Selects Par 1*/
div + p     /* Selects Par 3*/
div ~ p     /* Selects Par 3 and Par 3*/

CSS Attribute Selectors

CSS attribute selectors select elements based upon attributes and attribute values.

   
[attribute] Select elements with attribute.
[attribute=”value”] Selects elements with attribute=”value”
[attribute~=”value”] Selects elements with attribute containing “value” as a stand alone word. So “value-“ will not work.
[attribute|=”value”] Selects elements with attribute starting with “value-“ or matching exactly “value”
[attribute^=”value”] Selects elements with attributes starting with “value”
[attribute$=”value”] Selects elements with attributes ending with “value”
[attribute*=”value”] Selects elements with attributes containing “value”
/* Example */
    /* HTML */
<div attribute class="div1"/>
<div attribute="value" class="div2"/>
<div attribute="value-test" class="div3"/>
<div attribute="values" class="div4"/>

    /* CSS */
[attribute]{
    /* Styles div1, div2, div3, and div4 */
}
[attribute="value"]{
    /* Styles div2 */
}
[attribute~="value"]{
    /* Styles div2 */
}
[attribute|="value"]{
    /* Styles div2 and div3 */
}
[attribute^="value"]{
    /* Styles div2, div3, and div4 */
}
[attribute$="value"]{
    /* Styles div2 */
}
[attribute*="value"]{
    /* Styles div2, div3, and div4 */
}

Selector Specificity

/* If all the selectors target the same element then the one with the highest specificity will be applied. */
body div#header.container {
  /* Specificity: 0,1,1,2 */
  /* This has the highest specificity so it will be applied. */
}

#header {
  /* Specificity: 0,1,0,0 */
}

div.container {
  /* Specificity: 0,0,1,1 */
}

h1 {
  /* Specificity: 0,0,0,1 */
}

Variables in CSS

/* Declare vars*/
:root{/*Doesn't have to be in root, but it is recommended. Root allows all css bodies to use the variables.*/
    --hex-var: #ffffff;
    --string-var: "string";
    --px-var: 10px;
}

/* Reference vars */
var(--var);

/* Sets the variable again */
.class{
    --hex-var: #000000;
}

JavaScript can be used to set variables in CSS.

/* JavaScript */
document.documentElement.style.setProperty("--var", "10px")

/* CSS */
:root{
    --var: 0;
}

JASS

Often times a jass.css file is used which has a lot of CSS utility classes which can be added and removed with JS to apply custom CSS easily.

How to hide scrollbar

.remove-scrollbar {
  -ms-overflow-style: none;  /* IE and Edge */
  scrollbar-width: none; /* Firefox */
}
.remove-scrollbar::-webkit-scrollbar {
  display: none; /* Chrome */
}

Tailwind

Resetting button styling