A Handbook of CSS Study Notes
A Handbook of CSS Study Notes
margin: properties are used to create space around elements, outside of any
defined borders.
margin: 20px; = all four margin are 20px
margin-top: 50px;
margin-right: 30px;
margin-bottom: 50px;
margin-left: 80px;
Shorthand:
margin: 25px 50px 75px 100px;
The Margin Collapse:
[1] Only Vertical Margin Collapse
[2] Bigger Margin Wins
[3] Margin Collapsing With Elements Without Anything Between
[4] Nesting Does Not Prevent Collapse
border: properties allow you to specify the style, width, and color of an element's
border.
CSS Visibility:
visibility: property specifies whether or not an element is visible.
visibility: visible|hidden|collapse|initial|inherit;
CSS Dimensions:
height & width: properties are used to set the height and width of an element.
height: fit-content|auto|length|initial|inherit;
width: fit-content|auto|value|initial|inherit;
To Sets the maximum & minimum height of an element:
max-height: none|length|initial|inherit;
min-height: length|initial|inherit;
To Sets the maximum & minimum width of an element:
max-width: none|length|initial|inherit;
min-width: length|initial|inherit;
CSS Overflow:
overflow: property controls what happens to content that is too big to fit into an
area.
overflow: visible|hidden|scroll|auto|initial|inherit;
overflow-x: visible|hidden|scroll|auto|initial|inherit;
overflow-y: visible|hidden|scroll|auto|initial|inherit;
overflow-wrap: normal|anywhere|break-word|initial|inherit;
CSS Text:
text-decoration: the property is used to set or remove decorations from the text.
text-decoration: none|overline|line-through|underline;
text-indent: the property is used to specify the indentation of the first line of a text.
text-indent: 50px;
letter-spacing: the property is used to specify the space between the characters
in a text.
letter-spacing: 5px;
word-spacing: the property is used to specify the space between the words in a
text.
word-spacing: 10px|-2px;
CSS cursor:
cursor: property specifies the mouse cursor to be displayed when pointing over an
element.
cursor: alias|all-scroll|auto|copy|progress|wait|not-allowed;
CSS Float & Clear:
float: the property is used for positioning and formatting content e.g. let an image
float left to the text in a container.
float: left|right|none|inherit|initial;
- When we use the float property, and we want the next element below
(not on right or left), we will have to use the clear property.
clear: property specifies what should happen with the element that is next to a
floating element.
clear: none|left|right|both|initial|inherit;
CSS Tables:
border: specify table borders in CSS.
border: 1px solid black;
border-collapse: property sets whether the table borders should be collapsed
into a single border.
border-collapse: collapse;
text-align: property sets the horizontal alignment (like left, right, or center) of the
content in <th> or <td>.
text-align: center;
vertical-align: property sets the vertical alignment (like top, bottom, or middle) of
the content in <th> or <td>.
vertical-align: bottom;
border-spacing: property sets the distance between the borders of adjacent
cells.
border-spacing: 15px;
empty-cells: property sets whether or not to display borders on empty cells.
empty-cells: show|hide|initial|inherit;
table-layout: property defines the algorithm used to layout table cells, rows, and
columns.
table-layout: fixed;
caption-side: property specifies the placement of a table caption.
caption-side: top|bottom|initial|inherit;
CSS Pseudo-classes:
a pseudo-class is used to define a special state of an element.
CSS Pseudo-elements:
A CSS pseudo-element is used to style specified parts of an element.
box-sizing: property defines how the width and height of an element are
calculated: should they include padding and borders, or not.
box-sizing: border-box;
box-sizing: content-box|border-box|initial|inherit;
CSS caret-color:
the property specifies the color of the cursor (caret) in inputs, textareas, or any
element that is editable.
caret-color: auto|color;
CSS pointer-events:
property defines whether or not an element reacts to pointer events.
pointer-events: auto|none;
CSS Transitions:
transition: allows you to change property values smoothly, over a given duration.
transition: property duration timing-function delay|initial|inherit;
transition: width .35s 0.5s ease-in-out;
transition-delay: property specifies when the transition effect will start, value is
defined in seconds (s) or milliseconds (ms).
transition-delay: time|initial|inherit;
transition-delay: 5s;
transition-property: specifies the name of the CSS property the transition effect
is for (the transition effect will start when the specified CSS property changes).
transition-property: none|all|property|initial|inherit;
transition-property: width;
CSS filter:
filter: defines visual effects (like blur and saturation) to an element (often <img>).
filter: grayscale(100%);
filter: blur() | brightness() | contrast() | drop-shadow() | grayscale() |
hue-rotate() | invert() | opacity() | saturate() | sepia() | url();
CSS gradients:
let you display smooth transitions between two or more specified colors.
CSS defines three types of gradients:
● Linear Gradients (goes down/up/left/right/diagonally).
● Radial Gradients (defined by their center).
● Conic Gradients (rotated around a center point).
CSS Linear Gradients:
Syntax:
background-image: linear-gradient(direction, color-stop1, color-stop2, ...);
background-image: linear-gradient(to right, red , yellow);
use angles:
background-image: linear-gradient(180deg, red, yellow);
For Parent(container):
display: flex;
flex-direction: defines in which direction the container wants to stack the flex items.
flex-direction: row|row-reverse|column|column-reverse;
flex-wrap: specifies whether the flexible items should wrap or not.
flex-wrap: nowrap|wrap|wrap-reverse;
flex-flow: is a shorthand property for [Flex-Direction] + [Flex-Wrap].
flex-flow: row-reverse wrap;
justify-content: property aligns the flexible container's items when the items do not
use all available space on the main-axis (horizontally).
justify-content: flex-start|flex-end|center|space-between|space-evenly;
align-items: property specifies the default alignment for items inside the flexible
container.
align-items: stretch|center|flex-start|flex-end|baseline;
align-content: property modifies the behavior of the flex-wrap property. It is similar
to align-items, but instead of aligning flex items, it aligns flex lines.
align-items: stretch|center|flex-start|flex-end|space-around;
For Child:
flex-grow: property specifies how much the item will grow relative to the
rest of the flexible items inside the same container.
flex-grow: number;
flex-shrink: property specifies how the item will shrink relative to the rest of the
flexible items inside the same container.
flex-shrink: number;
order: property specifies the order of a flexible item relative to the rest of the flexible
items inside the same container.
order: number;
flex-basis: property specifies the initial length of a flexible item.
flex-basis: number;
flex: property sets the flexible length on flexible items.
flex: flex-grow flex-shrink flex-basis|auto;
CSS Grid:
There are two ways to set the Grid property:
For Parent(container):
display: grid;
grid-template-rows: property specifies the number (and the heights) of the rows in
a grid layout.
grid-template-rows: auto|max-content|min-content|fr|repeat();
grid lines: The lines between columns are called column lines, and lines between
rows are called row lines.
grid-column-start: 1;
grid-column-end: 3;
grid-row-start: 1;
grid-row-end: 3;
align-content: used to vertically align the whole grid inside the container.
align-content: space-evenly|space-around|start|end|center;
CSS 2D Transforms:
CSS transforms allow you to move, rotate, scale, and skew elements.
With the CSS transform property you can use the following 2D transformation
methods:
translate(): moves an element from its current position (according to the parameters
given for the X-axis and the Y-axis).
transform: translate(50px, 100px);
rotate(): rotates an element clockwise or counter-clockwise according to a given
degree.
transform: rotate(20deg);
scale(): increases or decreases the size of an element (according to the parameters
given for the width and height).
transform: scale(2, 3);
skew(): method skews an element along the X and Y-axis by the given angles.
transform: skewX(20deg);
CSS 3D Transforms:
CSS transforms allow you to move, rotate, scale, and skew elements.
With the CSS transform property you can use the following 3D transformation
methods:
perspective-origin: property defines from which position the user is looking at the
3D-positioned element.
perspective-origin: x-axis y-axis;
animation-fill-mode: a style for the element when the animation is not playing.
animation-fill-mode: none|forwards|backwards|both;
.class1.class2: Selects all elements with both name1 and name2 set within its class
attribute
.name1.name2
element.class: Selects all <p> elements with class="intro"
p.intro
element>element: Selects all <p> elements where the parent is a <div> element
div > p
element+element: Selects the first <p> element that is placed immediately after
<div> elements
div + p
element1~element2: Selects every <ul> element that is preceded by a <p> element
p ~ ul
[attribute]: Selects all elements with a target attribute
[target]
[attribute=value]: Selects all elements with target="_blank"
[target=_blank]
[attribute~=value]: Selects all elements with a title attribute containing the word
"flower"
[title~=flower]
[attribute*=value]: Selects every <a> element whose href attribute value contains
the substring "w3schools"
a[href*="w3schools"]
[attribute^=value]: Selects every <a> element whose href attribute value begins
with "https"
a[href^="https"]
:first-child: Selects every <p> element that is the first child of its parent
p:first-child
:last-child: Selects every <p> element that is the last child of its parent
p:last-child
:first-of-type: Selects every <p> element that is the first <p> element of its parent
p:first-of-type
:last-of-type: Selects every <p> element that is the last <p> element of its parent
p:last-of-type
:only-child: Selects every <p> element that is the only child of its parent
p:only-child
:only-of-type: Selects every <p> element that is the only <p> element of its parent
p:only-of-type
The @media rule is used in media queries to apply different styles for different
media types/devices.
Using media queries are a popular technique for delivering a tailored style sheet
(responsive web design) to desktops, laptops, tablets, and mobile phones also for
print, screen, or speech:
CSS Battle
Front-End Mentor
Elzero Challenges
CSS References
MDN
Dev Docs
CSS Reference
W3schools
Tympanus
CSS Tricks
CSS Triggers
CSS Properties
Meiert
Contact me
FB - Hasaan Muhammed