CSS

CSS Overview Selectors Declarations Rule Sets Comments Reset/Normalize Origin Importance Order Specificity Inheritance Cascade Layers Inline Styles Internal Styles External Styles @import Absolute Units Relative Units Dynamic Viewport Angle Units Time Units Frequency Units: Resolution Units Keywords Color Formats Color Functions & Spaces Background Color Background Image Background Repeat Background Position Background Size Background Attachment Background Shorthand Multiple Backgrounds Linear Gradients Radial Gradients Conic Gradients Font Family Font Size Font Weight Font Style Line Height Text Align Text Decoration Text Transform Letter Spacing Word Spacing Text Shadow Text Wrap Variable Fonts Content Box Padding Box Border Box Margin Box Box Sizing Property Margin Padding Border Outline Box Shadow Block Display Inline Display Inline Block Display Static Position Relative Position Absolute Position Fixed Position Sticky Position Top Element Position Right Element Position Bottom Element Position Left Element Position Z Index Flexbox Box Layout Display Flex Flex Direction Flex Wrap Justify Content Align Items Align Content Gap, Row Gap & Column Gap Flex Grow Flex Shrink Flex Basis Flex Shorthand Order Property Align Self Practical Applications CSS Grid Layout Grid Display Grid Template Columns Grid Template Rows Grid Template Areas Justify Items Grid Auto Columns Justify Self Nested Grids Responsive Web Design Min Width Max Width Orientation Logical Operators Pointer Hover Prefers Color Scheme Fluid Images Flexible Typography Viewport Width Advanced CSS Features Defining variables Using variables Scope & Inheritance of CSS Variables Property Value Fallback Practical Applications :Hover :Active :Focus :Focus Visible :Visited :Link :First Child :Last Child :Nth Child :Nth of Type :Empty :Checked :Disabled :Enabled :Valid :Invalid :Required :Has :Not :Is :Where ::Before Pseudo Element ::After Pseudo Element ::First Letter ::First Line ::Selection ::Marker CSS 2D Transformations CSS 3D Transformations Transform Origin Transform Style Backface Visibility Transition Property Transition Duration Transition Timing Function Transition Delay Transition Shorthand Ease Timing Function Linear Timing Function Ease In Timing Function Ease Out Timing Function Ease In Out Timing Function Cubic Bezier Function Animations (@keyframes) Defining @keyframes Animation Name CSS Animation Duration Animation Timing Function CSS Animation Delay CSS Animation Iteration Count Animations Direction CSS Animation Fill Mode CSS Animation Play State CSS Filter Blur CSS Filter Brightness CSS Filter Contrast() CSS Drop Shadow CSS Grayscale CSS Hue Rotate CSS Invert CSS Opacity CSS Saturate CSS Sepia Mix Blend Mode Background Blend Mode Object Fit & Object Position Scroll Snap Type Scroll Snap Align Scroll Padding Scroll Margin Scroll Triggered Animations JS Variables

:Active


The :active pseudo-class applies styles to an element during the time a user is activating it, such as when a link or button is being clicked.

Example 1: Button Active State

/* Style for a button */
.my-button {
  background-color: #28a745;
  color: white;
  padding: 10px 20px;
  border: none;
  cursor: pointer;
}

/* Style for the button when it is being clicked */
.my-button:active {
  background-color: #218838;
  transform: translateY(2px);
}

Explanation

When the button is clicked, its background color darkens, and it moves down slightly, giving the user a sense of pressing the button.


Example 2: Link Active State

/* Style for a link */
.my-link {
  color: #dc3545;
  transition: color 0.2s ease;
}

/* Change the color of the link when it is being clicked */
.my-link:active {
  color: #c82333;
}

Explanation

This code changes the color of a link at the moment it is clicked, providing immediate feedback to the user that their action has been registered.


Example 3: Div Active State

/* Style for a clickable div */
.clickable-div {
  padding: 20px;
  border: 2px solid #ffc107;
  cursor: pointer;
}

/* Change the border color and background when the div is active */
.clickable-div:active {
  background-color: #ffc107;
  color: white;
}

Explanation

This makes a div element behave like a button. When clicked, the background and border colors change, indicating an active state.


Example 4: Icon Active State

/* Style for an icon */
.my-icon {
  font-size: 24px;
  color: #17a2b8;
  cursor: pointer;
  transition: transform 0.2s ease;
}

/* Scale the icon down when it is active */
.my-icon:active {
  transform: scale(0.9);
}

Explanation

When the user clicks on the icon, it scales down slightly. This subtle animation gives the user a tactile sense of interaction with the icon.


Example 5: Input Field Active State

/* Style for an input field */
.my-input {
  border: 1px solid #ced4da;
  padding: 8px;
}

/* Change the border color of the input field when it is active */
.my-input:active {
  border-color: #007bff;
}

Explanation

While a user is clicking and holding down on the input field, the border color will change, indicating that the element is currently being interacted with.