Code Snippets
CSS Snippets
Base Structure
CSS Rule
selector {
property: value;
}
Inline CSS
<p style="color: red;">Text</p>
External CSS
<link rel="stylesheet" href="styles.css">
Internal CSS
<style>
p { color: blue; }
</style>
Selectors
Class Selector
.className {
color: blue;
}
ID Selector
#myId {
font-size: 20px;
}
Element Selector
p {
margin: 10px;
}
Universal Selector
* {
padding: 0;
}
Layout
Flexbox
.container {
display: flex;
}
Grid
.container {
display: grid;
grid-template-columns: 1fr 1fr;
}
Float Layout
.left {
float: left;
width: 50%;
}
Position Absolute
.box {
position: absolute;
top: 10px;
}
Responsive Design
Media Query
@media (max-width: 600px) {
body {
background-color: lightblue;
}
}
Viewport Meta
<meta name="viewport" content="width=device-width, initial-scale=1.0">
Relative Units
.box {
width: 50vw;
height: 20vh;
}
Min/Max Width
.container {
max-width: 1200px;
min-width: 300px;
}
Back to categories