Chapter 1 Chapter 2 Chapter 3 Chapter 4 Chapter 5 Chapter 6 Chapter 7 Chapter 8 Chapter 9 Chapter 10 Chapter 11 Chapter 12 Chapter 13 Chapter 14
Chapter 4

CSS3 Effects & Improved Selectors

Rounded corners, shadows, gradients, transforms and the new CSS3 selectors.


CSS3 Key Features

FeatureExample
Rounded cornersborder-radius: 12px;
Box shadowbox-shadow: 4px 4px 12px rgba(0,0,0,.25);
Gradientsbackground: linear-gradient(135deg, #0891B2, #7C3AED);
Text shadowtext-shadow: 2px 2px 4px rgba(0,0,0,.35);
Opacity / RGBAbackground-color: rgba(8,145,178,.6);
Transformstransform: rotate(45deg) scale(1.2);
Multiple columnscolumn-count: 3; column-gap: 1.5rem;
Transitions & animationtransition: all .3s ease-in-out;

CSS3 in Practice — Code Example

.card {
  padding: 2rem;
  width: 300px;

  /* Rounded corners */
  border-radius: 16px;

  /* Gradient background */
  background: linear-gradient(135deg, #0891B2, #7C3AED);

  /* Shadow */
  box-shadow: 0 8px 24px rgba(0, 0, 0, .25);

  /* Transition for hover effect */
  transition: transform .3s ease, box-shadow .3s ease;
}

.card:hover {
  transform: translateY(-6px) scale(1.02);
  box-shadow: 0 16px 40px rgba(0, 0, 0, .35);
}
  • border-radius creates rounded corners without images.
  • linear-gradient replaces gradient images.
  • box-shadow eliminates the need for shadow images.
  • transition animates property changes smoothly.
  • transform allows 2D/3D manipulation.

Vendor prefixes are rarely needed in modern browsers.

CSS3 Improved Selectors

SelectorMatches
[attr^="value"]Attribute starts-with — e.g. links starting with https
[attr$="value"]Attribute ends-with — e.g. images ending in .png
[attr*="value"]Attribute contains — flexible substring matching
:nth-child(n)Select by position — e.g. every 2nd row in a table
:first-child / :last-childFirst / last child of its parent
:checkedChecked checkbox/radio inputs
:not(selector)All elements that do NOT match the given selector
:focus-visibleShow the focus ring only for keyboard users — improves UX

Activity — complete the code

Complete the code correctly to mark this lesson as complete automatically.

Complete the CSS3 card effect.

.card {
border-radius: ;
background: -gradient(135deg, #0891B2, #7C3AED);
box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
transition: transform .3s ease;
}
 
.card:hover {
transform: translateY(-6px) (1.02);
}