WebBitz HTML & CSS Cheatsheet

CSS Cheatsheet

Basic Selectors

* {
  margin: 0;
  padding: 0;
} /* universal selector */

body {
  background-color: #1e1e1e;
  color: #f0f0f0;
  font-family: Arial, sans-serif;
} /* element selector */

#main {
  padding: 20px;
} /* ID selector */

.container {
  max-width: 1200px;
  margin: 0 auto;
} /* class selector */

h1, h2, h3 {
  color: cyan;
} /* group selector */

Box Model

.box {
  width: 300px;
  height: 200px;
  padding: 10px;
  margin: 20px;
  border: 2px solid #ccc;
  box-sizing: border-box;
}

Positioning

.static-box { position: static; }
.relative-box { position: relative; top: 10px; left: 10px; }
.absolute-box { position: absolute; top: 0; right: 0; }
.fixed-box { position: fixed; bottom: 10px; left: 10px; }
.sticky-box { position: sticky; top: 0; }

Display Types

.block { display: block; }
.inline { display: inline; }
.flex { display: flex; }
.grid { display: grid; }
.none { display: none; }

Flexbox

.flex-container {
  display: flex;
  flex-direction: row; /* or column */
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

Grid

.grid-container {
  display: grid;
  grid-template-columns: 1fr 2fr;
  grid-template-rows: auto auto;
  gap: 20px;
}

Typography

.text {
  font-size: 16px;
  font-weight: bold;
  font-style: italic;
  line-height: 1.5;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #fff;
}

Colors

.color-named { color: red; }
.color-hex { color: #ff5733; }
.color-rgb { color: rgb(255, 87, 51); }
.color-rgba { color: rgba(255, 87, 51, 0.5); }
.color-hsl { color: hsl(12, 100%, 60%); }

Borders & Shadows

.box-style {
  border: 1px solid #ccc;
  border-radius: 8px;
  box-shadow: 2px 2px 8px rgba(0, 0, 0, 0.2);
}

Backgrounds

.background {
  background-color: #333;
  background-image: url("bg.jpg");
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

Transitions

.button {
  transition: background-color 0.3s ease, transform 0.2s;
}
.button:hover {
  background-color: #ff4081;
  transform: scale(1.05);
}

Animations

@keyframes fadeIn {
  0% { opacity: 0; }
  100% { opacity: 1; }
}
.fade {
  animation: fadeIn 1s ease-in-out;
}

Pseudo-classes

a:hover { color: yellow; }
input:focus { border-color: deepskyblue; }

Pseudo-elements

p::first-letter {
  font-size: 200%;
}
div::after {
  content: "★";
  color: gold;
}

Media Queries

@media (max-width: 768px) {
  body {
    font-size: 14px;
  }
  .flex-container {
    flex-direction: column;
  }
}

Z-Index

.layer {
  position: absolute;
  z-index: 10;
}

Opacity

.transparent {
  opacity: 0.5;
}

Overflow

.scroll-box {
  width: 200px;
  height: 100px;
  overflow: auto;
}

Cursor Styles

.pointer { cursor: pointer; }
.wait { cursor: wait; }

Visibility

.hidden {
  visibility: hidden;
}