CSS Flashcards
pseudo classes
:hover
:visited
:focus
:nth-child(even)
:invalid:not(:focus)
pseudo elements
a::first-letter
p::before
p::after
specificity
Inline Styles: 1000
IDs: 100
Classes: 10
Pseudo-Classes: 10
Attributes: 10
Elements: 1
Pseudo-Elements: 1
whichever has highest total will apply
css units
- px
- em- relative to font size
- rem - relative to root element font size
block vs inline, inline-block
block elements start on new line and take entire width of parent
Box model
vertical margins collapse
margin, border, padding, content
Box sizing
width by default considers only the content not the padding and border
default - content-box
border-box- takes care of padding and border
Position
default - static
fixed- fixed based on browser, pass left, right
relative - relative position, pass bottom, left
sticky - relative then fixed when scrolled
absolute - absolute to page, if parent is relative then absolute will be relative to that
float
left, right
clear: both
clear: right
clear: left
flex
A layout model, also known as the Flexible Box Layout Module, particularly useful for building responsive designs with row or column layouts.
display: flex
flex-direction - row, column, row-reverse, column-reverse
justify-content - flex-start, flex-end, center, space-around, space-between, space-evenly
align-items - Determines how elements are positioned along the cross-axis - flex-start, flex-end, center, baseline, stretch
flex-wrap - wrap, nowrap, wrap-reverse
align-content: Determines how lines are positioned along the cross-axis when flex items are wrapping on multiple lines. Possible values are flex-start, flex-end, center, space-around, space-between, and stretch.
flex-flow: A shorthand for flex-direction and flex-wrap.
gap
Flex items
flex-grow
align-self
flex-basis
flex: <flex-grow>, <flex-shrink>, <flex-basis>
order</flex-basis></flex-shrink></flex-grow>
Media queries
@media (max-width: 600px) { p { color: red; } }
transition
transition: width 1s linear 2s;
to add to multiple properties use comma separate property and other values or use all
css animation
@keyframes animation-name { from { property: value; property: value; } 50% { property: value; property: value; } to { property: value; property: value; } }
Usage
animation: move 3s ease infinite alternate 2s;
animation-name
animation-duration
animation-fill-mode: forwards, backwards, both
animation-direction: normal, reverse, alternate, alternate-reverse
animation-iteration-count: number, infinite
animation-timing-function
transform
transform: rotate(180deg), translate(20px)
css grid
display: grid; grid-template-columns: auto auto auto auto; grid-template-rows: 80px 200px; justify-content: space-evenly; align-content: center;
grid-template-areas
grid-area
use grid-template-areas with grid-template-columns when required. use . if nothing is there in area
For grid items
place the item from 1 to 5 column grid-column: 1 / 5; start from 1 and span 3 columns grid-column: 1 / span 3; grid-area: footer; template areas tell how much the spans each item should take grid-template-areas: 'header header header header header header' 'menu main main main right right' 'menu footer footer footer footer footer';
CSS tooltip
<section> <div class="tooltip"> Hover over me sf asdf safds <span class="tooltiptext">Tooltip text</span> </div> </section>
.tooltip { position: relative; display: inline-block; cursor: pointer; } .tooltiptext { display: block; background: black; padding: 5px 10px; border-radius: 5px; color: white; position: absolute; bottom: 125%; text-align: center; transform: translateX(50%); } .tooltip:hover .tooltiptext{ display: block; } .tooltip .tooltiptext::after{ content: ''; position: absolute; border: 6px solid black; top: 100%; left: 50%; margin-left: -6px; border-color: black transparent transparent transparent }