CSS Cheatsheet
Published: 2023-09-07 12:00:40

CSS is a fundamental technology for designing and styling web content. This cheat sheet provides a quick reference to commonly used CSS properties, selectors, and techniques. Whether you're a beginner or an experienced developer, this cheat sheet will help you enhance your web design skills.

## Table of Contents

1. [Selectors](#selectors)
2. [Box Model](#box-model)
3. [Positioning](#positioning)
4. [Typography](#typography)
5. [Colors](#colors)
6. [Backgrounds](#backgrounds)
7. [Borders](#borders)
8. [Transforms](#transforms)
9. [Transitions](#transitions)
10. [Flexbox](#flexbox)
11. [Grid Layout](#grid-layout)

## Selectors

### Element Selector

```css
p {
  /* Selects all <p> elements */
}
```

### Class Selector

```css
.button {
  /* Selects all elements with class="button" */
}
```

### ID Selector

```css
#header {
  /* Selects the element with id="header" */
}
```

### Descendant Selector

```css
article p {
  /* Selects all <p> elements inside <article> elements */
}
```

### Pseudo-class Selector

```css
a:hover {
  /* Selects links on hover */
}
```

### Universal Selector

```css
* {
  /* Selects all elements */
}
```

## Box Model

### Width and Height

```css
.box {
  width: 200px;
  height: 100px;
}
```

### Margin

```css
.box {
  margin: 10px;
}
```

### Padding

```css
.box {
  padding: 10px;
}
```

### Border

```css
.box {
  border: 1px solid #000;
}
```

### Box Sizing

```css
.box {
  box-sizing: border-box;
}
```

## Positioning

### Position

```css
.element {
  position: relative;
  /* Other values: absolute, fixed, static */
}
```

### Float

```css
.image {
  float: left;
  /* Other values: right */
}
```

### Flexbox

```css
.container {
  display: flex;
  justify-content: center;
  align-items: center;
}
```

### Grid Layout

```css
.grid-container {
  display: grid;
  grid-template-columns: 1fr 2fr;
}
```

## Typography

### Font Family

```css
body {
  font-family: Arial, sans-serif;
}
```

### Font Size

```css
h1 {
  font-size: 24px;
}
```

### Font Weight

```css
strong {
  font-weight: bold;
}
```

### Text Alignment

```css
p {
  text-align: center;
  /* Other values: left, right, justify */
}
```

## Colors

### Color Property

```css
.element {
  color: #333;
}
```

### Background Color

```css
.container {
  background-color: #f0f0f0;
}
```

### Transparency

```css
.overlay {
  background-color: rgba(0, 0, 0, 0.5);
}
```

## Backgrounds

### Background Image

```css
.header {
  background-image: url('bg.jpg');
  background-size: cover;
}
```

### Background Repeat

```css
.tile {
  background-repeat: no-repeat;
  background-size: 100% 100%;
}
```

## Borders

### Border Radius

```css
.button {
  border-radius: 5px;
}
```

### Border Color

```css
.input {
  border: 1px solid #ccc;
}
```

## Transforms

### Scale

```css
.box {
  transform: scale(1.2);
}
```

### Rotate

```css
.card {
  transform: rotate(45deg);
}
```

## Transitions

### Transition Property

```css
.button {
  transition: background-color 0.3s ease;
}
```

### Hover Effect

```css
.button:hover {
  background-color: #007bff;
  color: #fff;
}
```

## Flexbox

### Flex Container

```css
.container {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
}
```

## Grid Layout

### Grid Container

```css
.grid-container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
```

This cheatsheet provides a concise reference to common CSS properties and techniques. Use it as a quick guide while working on your web projects to create beautiful and responsive designs.

*Estimated Reading Time: 5 minutes*