CSS3 Effects & Improved Selectors
Rounded corners, shadows, gradients, transforms and the new CSS3 selectors.
CSS3 Key Features
| Feature | Example |
|---|---|
| Rounded corners | border-radius: 12px; |
| Box shadow | box-shadow: 4px 4px 12px rgba(0,0,0,.25); |
| Gradients | background: linear-gradient(135deg, #0891B2, #7C3AED); |
| Text shadow | text-shadow: 2px 2px 4px rgba(0,0,0,.35); |
| Opacity / RGBA | background-color: rgba(8,145,178,.6); |
| Transforms | transform: rotate(45deg) scale(1.2); |
| Multiple columns | column-count: 3; column-gap: 1.5rem; |
| Transitions & animation | transition: 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-radiuscreates rounded corners without images.linear-gradientreplaces gradient images.box-shadoweliminates the need for shadow images.transitionanimates property changes smoothly.transformallows 2D/3D manipulation.
Vendor prefixes are rarely needed in modern browsers.
CSS3 Improved Selectors
| Selector | Matches |
|---|---|
[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-child | First / last child of its parent |
:checked | Checked checkbox/radio inputs |
:not(selector) | All elements that do NOT match the given selector |
:focus-visible | Show 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);}