hi, this is dave's cheatsheet!
element/tag list
Quoted text
Inline code
Preformatted block of code
css usage (cascading style sheets)
<p style="color: red;">Hello</p>
<style>
p {
color: red;
}
</style>
<link rel="stylesheet" href="styles.css">
Selector Type | Example | Definition |
---|---|---|
Element | p | Targets all <p> tags |
Class | .box | Targets elements with class="box". Reuseable |
ID | #main | Targets element with id="main". Should be used once. Better alternative to inline CSS |
Universial | * | Targets all elements in the page |
Descendant | div p | Targets <p> inside a <div> |
Child | div > p | Direct child <p> of <div>, nothing else |
Pseudo-class | a:hover | Styles <a> when hovered |
Property | Example | Definition |
---|---|---|
color | color: red; | Text color |
background | background-color: #fff; | Background color |
font-size | font-size: 20%; | Size of text |
margin | margin: 10px; | Space outside the element |
padding | padding: 5px; | Space inside the element |
border | border: 1px solid #000; | Border around the element |
display | display: flex; | Layout behavior |
position | position: absolute; | Positioning in the page |
text-align | text-align: center; | Aligns text inside the element |
Type of Selector | Example | Priority |
---|---|---|
Inline Styles | style="" in HTML | Highest |
ID | #id | High |
Class / Attribute / Pseudo-class | .class, a:hover | Medium |
Element | p, div | Low |
Universal | * | Lowest |
p {
color: blue !important;
}
p#special {
color: red;
}
HTML
<p id="special">This will be blue, not red!</p>
helpful tips using html + css
<div class="box-model">
<div class="margin">
<div class="border">
<div class="padding">
<div class="content"> Content :) </div>
</div>
</div>
</div>
</div>
.box-model * {
text-align: center;
line-height: 50px;
font-family: sans-serif;
}
.margin {
background: #d4e8ff;
padding: 20px;
border-radius: 6px;
}
.border {
border: 5px solid #a0bad8;
padding: 20px;
}
.padding {
background: #7088bd;
padding: 20px;
}
.content {
background: #3b4f74;
height: 50px;
border-radius: 6px;
}
.container {
display: flex;
justify-content: space-between;
align-items: center;
}