Phase 2CSS Fundamentals

#8 Backgrounds and borders

background, gradients, border-radius, shadows

Backgrounds

Background properties
.hero {
  background-color: #1a1a2e;
  background-image: url("hero-bg.jpg");
  background-size: cover;       /* Fill container */
  background-position: center;
  background-repeat: no-repeat;
  background-attachment: fixed;  /* Parallax effect */
}

Gradients

CSS gradients
/* Linear gradient */
.gradient-1 {
  background: linear-gradient(135deg, #3b82f6, #8b5cf6);
}

/* Radial gradient */
.gradient-2 {
  background: radial-gradient(circle at top left, #3b82f6, transparent);
}

/* Conic gradient */
.gradient-3 {
  background: conic-gradient(from 45deg, #f97316, #eab308, #22c55e, #3b82f6, #f97316);
}

/* Multiple backgrounds */
.layered {
  background:
    linear-gradient(rgba(0,0,0,0.5), rgba(0,0,0,0.5)),
    url("photo.jpg") center / cover no-repeat;
}

Borders

Border properties
.card {
  border: 1px solid #e0dbd4;
  border-radius: 12px;
}

/* Individual sides */
.divider {
  border-top: 2px solid #3b82f6;
  border-bottom: none;
}

/* Outline (does not affect layout) */
.focus-ring {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
}

Shadows

Box and text shadows
.card {
  /* x-offset | y-offset | blur | spread | color */
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1),
              0 2px 4px -2px rgba(0, 0, 0, 0.1);
}

.card:hover {
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.15);
}

/* Inset shadow */
.inset {
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Text shadow */
h1 {
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
}

Your turn

Try the background and border commands below:

terminal — browser
user@stemlegacy:~$